DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   Delay loading advertisements (http://www.daniweb.com/forums/thread53491.html)

cscgal Aug 27th, 2006 12:27 pm
Delay loading advertisements
 
Is there ANY method to delay the loading of 3rd party javascript advertisements until the rest of the page has finished loading? When my ad server gets sluggish, it delays the output of my site, which is killer.

And yes, I already know about using position:absolute to place the JS code at the bottom of the page and absolutely position the ad where I want it. Unfortunately that's really hard to do with my layout, however.

Sailor_Jerry Aug 27th, 2006 1:52 pm
Re: Delay loading advertisements
 
Try adding the "defer" attribute to the end of your script tags.
i.e.(<script type='"text/javascript" defer>your javascript</script>

With this attribute, the code inside the script tags will only get executed when the page has been loaded completely.

cscgal Aug 27th, 2006 1:55 pm
Re: Delay loading advertisements
 
Thanks. Unfortunately, this only works for script files inside <head>. I've actually just succumbed to the pressure and did a whole bunch of fancy absolute positioning tricks. So we'll see how it goes :)

Sailor_Jerry Aug 27th, 2006 2:33 pm
Re: Delay loading advertisements
 
Quote:

Originally Posted by cscgal (Post 246976)
Thanks. Unfortunately, this only works for script files inside <head>. I've actually just succumbed to the pressure and did a whole bunch of fancy absolute positioning tricks. So we'll see how it goes :)



Here is a quick test with the scipt in the body. If you remove defer from the script tag and run the html, you will get a script error.

<html>
<head>
<style>#TestDefer{display:none;}</style>
</head>


<body>
<script language="javascript" type="text/javascript" defer>
alert(document.getElementById('TestDefer').innerHTML);
</script>

<div id=TestDefer >
This Text should display in the alert if defer is present in the script.
</div>
</body>
</html>

:)


All times are GMT -4. The time now is 2:36 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC