943,915 Members | Top Members by Rank

Ad:
Feb 25th, 2006
0

Delay JavaScript execution

Expand Post »
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?
Similar Threads
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Feb 28th, 2006
1

Re: Delay JavaScript execution

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)
  1. <body onload="doWhatever();">
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
Mar 5th, 2006
1

Re: Delay JavaScript execution

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]
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Apr 4th, 2006
0

Re: Delay JavaScript execution

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!
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Apr 4th, 2006
0

Re: Delay JavaScript execution

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).
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005
Apr 4th, 2006
0

Re: Delay JavaScript execution

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.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Jun 17th, 2007
0

Re: Delay JavaScript execution

CSGal, did you ever find a solution to this crazy problem? I've been wrestling with this problem as well.

Thanks!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
GobBluth is offline Offline
1 posts
since Jun 2007
Jun 21st, 2007
0

Re: Delay JavaScript execution

Maybe this will work:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>My Web Page</title>
  4. <script language="javascript">
  5. function LoadTrigger(){
  6. document.getElementById("AdServer").innerHTML = "<iframe.....></iframe>";
  7. }
  8. window.onload = LoadTrigger;
  9. </script>
  10. </head>
  11. <body>
  12. <!-- Placeholder for the iframe -->
  13. <div id="AdServer"></div>
  14. </body>
  15. </html>
Last edited by Ziggy Rocks; Jun 21st, 2007 at 1:29 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ziggy Rocks is offline Offline
1 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: auto completion of the text box from previous entered values
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: video streaming





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC