使用 jquery 在页面后加载广告(脚本)

发布于 2024-10-17 03:05:20 字数 2351 浏览 2 评论 0原文

我正在尝试优化页面渲染和下载,但我陷入了这种情况...... 我想在页面加载结束时加载广告,我做了一个简单的测试 PAGE

代码:

<!DOCTYPE html>
<html lang="en">
  <head>   
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
          var AdBrite_Title_Color = '443E3E';
          var AdBrite_Text_Color = '443E3E';
          var AdBrite_Background_Color = 'D1CFCF';
          var AdBrite_Border_Color = '443E3E';
          var AdBrite_URL_Color = '443E3E';
          try{var AdBrite_Iframe=window.top!=window.self?2:1;var AdBrite_Referrer=document.referrer==''?document.location:document.referrer;AdBrite_Referrer=encodeURIComponent(AdBrite_Referrer);}catch(e){var AdBrite_Iframe='';var AdBrite_Referrer='';}
          $(document).ready(function(){                    
          });    
    </script>     
  </head>  
  <body style="background: #90EE90;">
  <div id="page" style="">              
      <div id="loginbox" style="position: fixed; top: 150px; left: 250px;">          
          <span style="white-space:nowrap;"> <!-- AD MUST BE HERE-->
          <a target="_top" 
             href="http://www.adbrite.com/mb/commerce/purchase_form.php?opid=1866421&afsid=1">
           <img src="http://files.adbrite.com/mb/images/adbrite-your-ad-here-banner-w.gif" 
              style="background-color:#443E3E;border:none;padding:0;margin:0;" 
              alt="Your Ad Here" width="11" height="60" border="0" />
          </a></span>        
      </div>                
    </div>     
  </body>
</html>

原来有 HTML 注释的地方有:

<script type="text/javascript">
document.write(String.fromCharCode(60,83,67,82,73,80,84));
document.write(' src="http://ads.adbrite.com/mb/text_group.php?sid=1866421&zs=3436385f3630&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">');
document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));
</script>

我需要使用 jquery 在页面后加载此元素,我尝试了很多解决方案,绑定 document.write 操作,添加 < /code> 元素但没有任何作用...

我真的需要帮助;)

I'm trying to optimize the page render and download and I'm stuck in this situation...
I'd like to load an advertise at the end of page load, I made a simple test PAGE

Code:

<!DOCTYPE html>
<html lang="en">
  <head>   
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
          var AdBrite_Title_Color = '443E3E';
          var AdBrite_Text_Color = '443E3E';
          var AdBrite_Background_Color = 'D1CFCF';
          var AdBrite_Border_Color = '443E3E';
          var AdBrite_URL_Color = '443E3E';
          try{var AdBrite_Iframe=window.top!=window.self?2:1;var AdBrite_Referrer=document.referrer==''?document.location:document.referrer;AdBrite_Referrer=encodeURIComponent(AdBrite_Referrer);}catch(e){var AdBrite_Iframe='';var AdBrite_Referrer='';}
          $(document).ready(function(){                    
          });    
    </script>     
  </head>  
  <body style="background: #90EE90;">
  <div id="page" style="">              
      <div id="loginbox" style="position: fixed; top: 150px; left: 250px;">          
          <span style="white-space:nowrap;"> <!-- AD MUST BE HERE-->
          <a target="_top" 
             href="http://www.adbrite.com/mb/commerce/purchase_form.php?opid=1866421&afsid=1">
           <img src="http://files.adbrite.com/mb/images/adbrite-your-ad-here-banner-w.gif" 
              style="background-color:#443E3E;border:none;padding:0;margin:0;" 
              alt="Your Ad Here" width="11" height="60" border="0" />
          </a></span>        
      </div>                
    </div>     
  </body>
</html>

Where there is the HTML Comment originally there were:

<script type="text/javascript">
document.write(String.fromCharCode(60,83,67,82,73,80,84));
document.write(' src="http://ads.adbrite.com/mb/text_group.php?sid=1866421&zs=3436385f3630&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">');
document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));
</script>

I need to load this element after page using jquery, I tried many solution, binding document.write action, adding a <script></script> element but nothing works...

I really need an help ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清浅ˋ旧时光 2024-10-24 03:05:20

最后我解决了我的问题,使用 jQuery 在页面加载后加载 iframe...

为 ADV 创建一个特定页面,然后加载 iframe

$(document).ready(function(){     
  $('#advtop').html('<iframe src="http://www.blablabla.ext/ad.php?pos=top"></iframe>');
});

AD 脚本不会减慢页面加载速度,当文档准备好时,iframe 会放置在正确的位置,不会导致 ADV 替换所有内容,同时 ADV 也会获得正确的 URL 引用

希望这可以帮助某人...

At the end I solved my problem, loading an iframe after page load using jQuery...

Create a specific page for ADV, then loading the iframe

$(document).ready(function(){     
  $('#advtop').html('<iframe src="http://www.blablabla.ext/ad.php?pos=top"></iframe>');
});

The AD script won't slow the page load, and when the document is ready the iframe is placed in the correct position, without causing ADV replacing everything, also ADV get the correct URL referrer

Hope this could help someone...

鹿港小镇 2024-10-24 03:05:20

实际上,我在 newsweek.com 网站上使用了一个名为 writeCapture.js 的脚本来完成此操作。它拦截 document.write 方法并将所有广告代码切换为 html 注入(真的很奇特!)。

无论如何,要查看一个工作示例(newsweek.comthedailybeast.com 和在控制台中输入 newsweek.ads.refresh()。至于文档,writeCapture 站点将解释一切。

I actually did this on the newsweek.com site using a script called writeCapture.js. It intercepts the document.write method and switches all the ad code to html injection (really fancy stuff!).

Anyway, to see a working example hit up (newsweek.com) thedailybeast.com and enter newsweek.ads.refresh() in the console. As for documentation, the writeCapture site will explain everything.

相思故 2024-10-24 03:05:20

我在我的网站上使用以下代码执行此操作:

function adScript(){
    var s1 = document.createElement('script');
    s1.src='http://put_your_url_here';
    s1.type = 'text/javascript';
    s1.onload = function(){
         // initialize the page to use the script
    }
    document.getElementsByTagName('head')[0].appendChild(s1);
}
adScript();

本质上,“adScript”函数是在“$(document).ready”jQuery 事件中调用的。这会动态创建脚本标签。浏览器加载远程脚本。加载后,您的“onload”函数就会被执行。

希望有帮助。

鲍勃

I do this on my site using the following code:

function adScript(){
    var s1 = document.createElement('script');
    s1.src='http://put_your_url_here';
    s1.type = 'text/javascript';
    s1.onload = function(){
         // initialize the page to use the script
    }
    document.getElementsByTagName('head')[0].appendChild(s1);
}
adScript();

Essentially, the 'adScript' function is called in the '$(document).ready' jQuery event. This dynamically creates a script tag. The browser loads the remote script. Once loaded, your 'onload' function is executed.

Hope that helps.

Bob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文