User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,383 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,063 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 13984 | Replies: 7
Reply
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,890
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 109
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Delay JavaScript execution

  #1  
Feb 25th, 2006
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Delay JavaScript execution

  #2  
Feb 28th, 2006
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.
<body onload="doWhatever();">
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Delay JavaScript execution

  #3  
Mar 5th, 2006
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]
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,890
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 109
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: Delay JavaScript execution

  #4  
Apr 4th, 2006
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!
Reply With Quote  
Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Delay JavaScript execution

  #5  
Apr 4th, 2006
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).
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,890
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 109
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: Delay JavaScript execution

  #6  
Apr 4th, 2006
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.
Reply With Quote  
Join Date: Jun 2007
Posts: 1
Reputation: GobBluth is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
GobBluth GobBluth is offline Offline
Newbie Poster

Re: Delay JavaScript execution

  #7  
Jun 17th, 2007
CSGal, did you ever find a solution to this crazy problem? I've been wrestling with this problem as well.

Thanks!
Reply With Quote  
Join Date: Jun 2007
Posts: 1
Reputation: Ziggy Rocks is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Ziggy Rocks Ziggy Rocks is offline Offline
Newbie Poster

Re: Delay JavaScript execution

  #8  
Jun 21st, 2007
Maybe this will work:

<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 12:29 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 1:04 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC