| | |
Delay JavaScript execution
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I use a third party ad server to deliver the advertisements on my site. There are two invocation methods: IFRAME and JavaScript. I currently use the IFRAME method because it allows the full webpage to render independently of the ads ... in other words, without slowing down browser rendering time contacting and downloading images or flash animation from a third party server. I don't want the page content to be delayed being displayed because of a slow ad server or large flash animated ad. However, the JavaScript version is more full featured. Is there a way that I could use the JavaScript version while telling the browser not to execute it until the end? What if I were to include the JavaScript via an external file instead of inline?
Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
don't know if this is what you are looking for or if it will help, but if you call a javascript function via the onload event in the body tag, it will not run until the page is fully loaded.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<body onload="doWhatever();">
Glad to help the csgal.
Campkev is correct. Here is how I do it.
[PHP]
<html>
<head>
<title>My Web Page</title>
<script type="text/javascript">
function LoadTrigger()
{
alert('This will fire after the page has finished loading.');
}
window.onload = LoadTrigger;
</script>
</head>
<body>
<p>
My Web Page is great!
</p>
</body>
</html>
[/PHP]
Campkev is correct. Here is how I do it.
[PHP]
<html>
<head>
<title>My Web Page</title>
<script type="text/javascript">
function LoadTrigger()
{
alert('This will fire after the page has finished loading.');
}
window.onload = LoadTrigger;
</script>
</head>
<body>
<p>
My Web Page is great!
</p>
</body>
</html>
[/PHP]
Thanks, guys. Appreciate the help! I will have to play around with this because my JavaScript code uses document.writes so I need to implement them inline where they belong.
Will work on it and let you guys know!
Will work on it and let you guys know! Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
To ensure the page is loaded before the add is drawn you can use a setTimeout(yourfunction,500) type mechanism in the onLoad.
You can also look at using the html dom to add innerHTML instead of using document.write
This can be done at any time... you could even set up a script that rotates your adds every minute or so (also by manipulating the innerHTML of DOM nodes).
You can also look at using the html dom to add innerHTML instead of using document.write
This can be done at any time... you could even set up a script that rotates your adds every minute or so (also by manipulating the innerHTML of DOM nodes).
Because I'm using a third party ad server, I don't have access to the script, itself (such as editing the document.writes). All I can do is call the <script> which is located on a remote server.
Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
•
•
Join Date: Jun 2007
Posts: 1
Reputation:
Solved Threads: 0
Maybe this will work:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <title>My Web Page</title> <script language="javascript"> function LoadTrigger(){ document.getElementById("AdServer").innerHTML = "<iframe.....></iframe>"; } window.onload = LoadTrigger; </script> </head> <body> <!-- Placeholder for the iframe --> <div id="AdServer"></div> </body> </html>
Last edited by Ziggy Rocks; Jun 21st, 2007 at 1:29 pm.
![]() |
Similar Threads
- JavaScript execution delay (JavaScript / DHTML / AJAX)
- JavaScript execution delay (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: auto completion of the text box from previous entered values
- Next Thread: video streaming
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxcode ajaxhelp animate api automatically beta boarder box bug calendar card checkbox child class column cookies createrange() css cursor decimal design dom download dropdown editor element error events explorer file firehose flash form forms google gwt html htmlform ie8 iframe image() images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jump listbox math matrixcaptcha microsoft mimic mp3 mp4 mysql object onmouseoutdivproblem onmouseover onreadystatechange parameters parent passing php player post problem progressbar rating regex runtime search select session shopping size sql star starrating stars stretch text textarea twitter validation w3c web website window windowofwords windowsxp wysiwyg xml xspf \n






