Load ad (script) after page using jquery

I'm trying to optimize the rendering and loading of a page, and I'm stuck in this situation ... I would like to load ads at the end of the page load, I did a simple PAGE test

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> 

In those cases where there is an HTML comment first, 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 the page using jquery, I tried many solutions by binding the document.write action, adding the <script></script> element, but nothing works ...

I really need help;)

+4
source share
3 answers

In the end, I solved my problem by loading an iframe after loading the page using jQuery ...

Create a specific page for ADV, then load the iframe

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

The AD script will not slow down the page loading, and when the document is ready, the iframe will be placed in the correct position, without forcing the ADV to replace everything, also the ADV will get the correct URL

Hope this can help someone ...

+2
source

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

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

+2
source

I do this on my website 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 jQuery '$ (document) .ready event. This dynamically creates a script tag. The browser loads the remote script. After loading, your onload function is executed.

Hope this helps.

Bean

0
source

Source: https://habr.com/ru/post/1339113/


All Articles