...

View Full Version : simple onload question - or so i think



superjoepsu
01-23-2009, 07:05 PM
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:


<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!

itsallkizza
01-26-2009, 09:04 AM
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.

superjoepsu
01-29-2009, 04:05 AM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum