Load ads last

Discussion in 'Javascript' started by matt@thephred.com, Nov 9, 2006.

  1. Guest

    Hello Everyone,
    We are serving up some regular ads that are calling for their content
    before the rest of our site.
    It's causing some load problems, so I'm investigating trying to defer
    the loading of ads until after the page has loaded.

    My first solution was to put the ad strings into an array of ads and
    have them looped through and attached to the body onload.

    Here is an example ad:
    var ads = [];
    ads.push('<scr' + 'ipt' + ' language="javascript"><!-- var dc=document;
    var date_ob=new Date();dc.cookie=\'h2=o; path=/;\';var
    bust=date_ob.getSeconds();if(dc.cookie.indexOf(\'e=llo\') <= 0 &&
    dc.cookie.indexOf(\'2=o\') > 0){dc.write(\'<scr\'+\'ipt
    language="javascript"
    src="http://mediapeople\');dc.write(\'/w/pop.cgi?sid=16453&m=2&tp=2&v=1.8&c=\'+bust+\'"></scr\'+\'ipt>\');date_ob.setTime(date_ob.getTime()+43200000);dc.cookie=\'he=llo;
    path=/; expires=\'+ date_ob.toGMTString();} // -->' + '</scr' + 'ipt>')
    ;

    function placeAds() {
    for(var i =0; i < ads.length; i++) {
    var fragment = document.createDocumentFragment();
    var div = document.createElement('div');
    div.innerHTML = ads;
    fragment.appendChild(div);
    document.body.appendChild(fragment);
    }
    }
    window.onload=placeAds;

    There are two problems:
    1. The <!-- comment actually stops the javascript from running with
    this tactic.
    2. When the javascript does run it rewrites the page. Doh!

    Does anyone have a more elegant solution for this?
    Thanks
    -matt
    , Nov 9, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray5531
    Replies:
    1
    Views:
    1,613
    Marc Jennings
    Apr 4, 2005
  2. Ray5531

    ads by google

    Ray5531, May 10, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    475
    Alan Silver
    May 17, 2005
  3. Chad Beckner
    Replies:
    3
    Views:
    10,015
    Chad Beckner
    Aug 11, 2005
  4. sangram
    Replies:
    16
    Views:
    1,955
  5. Johny
    Replies:
    8
    Views:
    371
Loading...

Share This Page