How to load the Advertising banner code after the website has been fully loaded?

Discussion in 'JavaScript' started by Mike80, Sep 21, 2011.

  1. #1
    HI :)
    How can i load the Advertising banner code after the website has been fully loaded?
    I searched google for a long time for this but i couldn't find any useful solution for it. I hop someone here can help me because this 2 Advertising banners slow me site load down.
     
    Mike80, Sep 21, 2011 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2
    first comment-out the add code inside its container..

    <div id="ad1"><!-- the ad code here --></div>
    <div id="ad2"><!-- the ad code here --></div>
    <script type="text/javascript">
    
       document.body.onload = function()
      {
         var ad1 = document.getElementById('ad1');
              ad1.innerHTML = ad1.firstChild.data;
         var ad2 = document.getElementById('ad2');
              ad2.innerHTML = ad2.firstChild.data;
      }
    
    </script>
    HTML:
     
    JohnnySchultz, Sep 22, 2011 IP
  3. Mike80

    Mike80 Well-Known Member

    Messages:
    103
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    THX i added this script to the website but i don't see any improvements in the loud time. :(

    
    <div id="ad1" style="text-align: center">
    <script type="text/javascript">
    var AdBrite_Title_Color = 'EFEFEF';
    var AdBrite_Text_Color = 'EFEFEF';
    var AdBrite_Background_Color = '2E2E2E';
    var AdBrite_Border_Color = '2E2E2E';
    var AdBrite_URL_Color = 'F26321';
    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='';}
    </script>
    <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=2016176&zs=3136305f363030&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">');document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));</script>
    </div>
    <script type="text/javascript">
       document.body.onload = function()
      {
         var ad1 = document.getElementById('ad1');
              ad1.innerHTML = ad1.firstChild.data;
      }
    </script>
    
    Code (markup):
     
    Mike80, Sep 22, 2011 IP
  4. Mike80

    Mike80 Well-Known Member

    Messages:
    103
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #4
    If i understand this right then i think i need to copy the code
    <div id="ad1"><!-- my ad code --></div>
    Code (markup):
    At the bottom of the </body> tag.
    And the javascript i place where the advertising banner should be displayed.
    But if i do that the advertising banner will not show up did i do something wrong?
     
    Mike80, Sep 22, 2011 IP
  5. mrmuggles

    mrmuggles Greenhorn

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #5
    Basically, what you want to do is to add the AD code with JavaScript on your page after the page is loaded.

    Here's how you call a function after the page is loaded

    function init() {
    // code here will get executed after load
    }
    // Call init on load
    window.onload = init;

    Now in your init() function, add the JavaScript code of your add to your page.

    Read
    http://unixpapa.com/js/dyna.html
    for more info!
     
    mrmuggles, Oct 7, 2011 IP
  6. Mike80

    Mike80 Well-Known Member

    Messages:
    103
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #6
    I tried this on he script of mycorrent new ad network but it doesn't work.

    <script language="javascript">
    function init(){
    <script src="http://cpm.biz/fixed.php?ad=60koq&u=ebykr4&w=160&h=600&s=d8i65b" type="text/javascript"></script>
    }
    window.onload=init;
    </script>
     
    Mike80, Oct 8, 2011 IP
  7. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #7
    Try changing post #3 to
    
    
    <div id="ad1" style="text-align: center">&nbsp;</div>
     <script type="text/javascript">
       document.body.onload = function()   {
         var AdBrite_Title_Color = 'EFEFEF';
        var AdBrite_Background_Color = '2E2E2E';
         var AdBrite_Border_Color = '2E2E2E';
         var AdBrite_URL_Color = 'F26321';
         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.write(String.fromCharCode(60,83,67,82,73,80,84));
        document.write('src="http://ads.adbrite.com/mb/text_group.php?sid=2016176&zs=3136305f363030&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">');
        document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));
         var ad1 = document.getElementById('ad1');
         ad1.innerHTML = ad1.firstChild.data;
      }
     </script>
    
    Code (markup):
    Note: I didn't test this, I just rewrote the order in which you did things, since doing it your way loaded the ad before the page finished loading - so there may be some errors.
     
    Rukbat, Oct 8, 2011 IP
  8. Mike80

    Mike80 Well-Known Member

    Messages:
    103
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #8
    Didn't work. Looks like iframe is the only way to do this. :(
     
    Mike80, Oct 8, 2011 IP
  9. nemanja.todic

    nemanja.todic Well-Known Member

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    130
    #9
    It's very simple and achievable. :)

    There is two approaches:

    -Using CSS: Set background-image through CSS and all major browsers will load it last. Your page will be rendered even before your images are loaded.
    -Using JS: Someone above gave an example but I think it wasn't completely right. You need to execute code that will load image after document is rendered( or "load"). This is easy. If you using jQuery you can use "onReady" event. If you're not, you can use:

    window.onload = function () { your code here; }

    Now, say you have a div with id "myBanners" somewhere in HTML. Inside it, you want your images to be stored, but right after page is loaded. In "onload" function do:

    -select div "myBanners"
    -Create new image tag
    -Place image tag inside myBanners div.

    So:

    
    var img = new Image();
    img.src = "pathToImage/image.jpg";
    document.getElementById('myBanners').appendChild(img);
    
    Code (markup):
    And there you go.

    I would advise not to use iFrame solution. There are couple of reasons ;)
     
    nemanja.todic, Oct 9, 2011 IP
  10. Telmo Neves

    Telmo Neves Greenhorn

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #10
    Hey there, I also have this same problem and cant solve it. Can anyone help me? I did not find any solution to this in the entire internet... I just know that scripts with sources can only be loaded before the document has finished loading.
     
    Telmo Neves, Dec 1, 2013 IP
  11. Mike80

    Mike80 Well-Known Member

    Messages:
    103
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #11
    Use the new "Asynchron" AdSense code.
     
    Mike80, Dec 1, 2013 IP
  12. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #12
    There's a big question that need to be asked and/or information you failed to provide that are pretty much required for anyone to provide a meaningful answer -- I find it disturbing people started posting code or attempting to answer without asking this...

    WHAT advertising service are you using and/or what does the code you already have look like?

    Everything people are saying here is complete nonsense without having that answered first! Adsense? Adbright? Some other scam? Without knowing what code you already have how can ANYONE possibly provide a meaningful and working answer?!? Herpafreakingderp people!

    ... of course my answer would be to rip the adverts out completely, but that's because I don't believe in advertising as a viable revenue source -- since don't see ads on websites as I run an adblock and set them up for EVERYONE I know and every machine that goes out my door, and trust online advertisers about as far as I could throw "The big stick". thinking them all a bunch of sleazeball scumbags... but then, I'm a pre dotcom-burst veteran.
     
    deathshadow, Dec 3, 2013 IP
  13. Mike80

    Mike80 Well-Known Member

    Messages:
    103
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #13
    Only a matter of time till users get punished for using a AdBlocker google is already doing this at Brazilian visitors. And i'm also doing this but for every user.
     
    Mike80, Dec 3, 2013 IP
  14. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #14
    Works both ways, anyone pulling that type of stunt is very likely to have users go "Yeah, and **** you too buddy!"

    Since there are plenty of other websites out there without that type of asshattery. I automatically assume anyone blocking users running an adblock is just trying to install malware, viruses, and other sleazy crap that means I don't want to visit that website in the first place -- same policy I have for sites that 'require' activeX or have no scripting off graceful degradation. People want to be sleazeball shits in making their websites, I'm going to call them and treat them as sleazeball shits.

    ... and when it comes to the Internet the past year or two, I've not seen so many desperate sleazeball shits since the year or two leading up to the original dotcom burst and it's corresponding "advertisting can pay for everything" grade A farm fresh manure.
     
    deathshadow, Dec 3, 2013 IP
  15. Mike80

    Mike80 Well-Known Member

    Messages:
    103
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #15
    Do your really think this forum and a lot of other big websites would still exists without Ads or premium accounts? Think again.
    And by the way i also saw a Ad revenue increase by punishing leechers (AdBlcokers) on my websites.
     
    Last edited: Dec 3, 2013
    Mike80, Dec 3, 2013 IP