Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts

    simple onload question - or so i think

    scenario: page loads with multiple ads. the banner ads are affecting the perceived load time of the rest of the page content. to address this, i'm trying to fire them off AFTER the page completely loads.

    i'm not proficient with JS by any stretch of the imagination, but i believe a solution could involve using onload. one thing of note is that i am not able to manipulate the body tag.

    is there a way, whether it be within the document or an external JS file, that i can somehow add an onload statement to these? i tried using a getElementById in an external JS file to replace the contents of an empty div with the snippets of JS below, but that loaded the entire page then fired off the JS on a new page.

    i feel there should be a simple way to do this. my trials by fire have seem to have gotten me close, but not all the way. it seems like i should be able to just drop a "window.onload = DISPLAY_AD(IncrementCounter(), 1);" in there and call it a day, but then again that's probably why i'm not a JS person in the first place.

    currently existing HTML:
    Code:
    <div id="left" class="ad">
      <script type="text/javascript">
      <!--
      DISPLAY_AD(IncrementCounter(), 1);
      //-->
      </script>
    </div>
    
    <div id="right" class="companion">
      <script type="text/javascript">
      <!--
      RIGHT_DISPLAY_AD(6);
      //-->
      </script>
    </div>
    anyways, any help/feedback would be appreciated. i can add more info if needed. thanks!

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Code:
    function addEventHandler(to_element,event,handler)
    	{
    	if (typeof(handler)=="string") handler = Function(handler);
    	var f = event.substr(0,2);
    	var e = (f=="on"||f=="On"||f=="ON"||f=="oN") ? event.substr(2) : event;
    	to_element.addEventListener ? to_element.addEventListener(event,handler,false) : to_element.attachEvent("on"+event,handler);
    	}
    
    addEventHandler(window,"load","DISPLAY_AD(IncrementCounter(),1);");
    addEventHandler(window,"load","RIGHT_DISPLAY_AD(6);");
    Of course I'm going to go ahead and assume those two functions are printing content rather than using DOM methods to insert the data, in which case you're going to need to rewrite them.

    Show one of those function's codes and I'll take a look.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • Users who have thanked itsallkizza for this post:

    superjoepsu (01-29-2009)

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by itsallkizza View Post
    Code:
    function addEventHandler(to_element,event,handler)
    	{
    	if (typeof(handler)=="string") handler = Function(handler);
    	var f = event.substr(0,2);
    	var e = (f=="on"||f=="On"||f=="ON"||f=="oN") ? event.substr(2) : event;
    	to_element.addEventListener ? to_element.addEventListener(event,handler,false) : to_element.attachEvent("on"+event,handler);
    	}
    
    addEventHandler(window,"load","DISPLAY_AD(IncrementCounter(),1);");
    addEventHandler(window,"load","RIGHT_DISPLAY_AD(6);");
    Of course I'm going to go ahead and assume those two functions are printing content rather than using DOM methods to insert the data, in which case you're going to need to rewrite them.

    Show one of those function's codes and I'll take a look.
    thanks, this indeed work!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •