homepage Welcome to WebmasterWorld Guest from 54.234.128.25
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Before onload
Is there a way to run a script before the page fully loads?
Jeremy_H




msg:3237798
 12:32 am on Jan 31, 2007 (gmt 0)

Hello,

When the page opens, I'm trying to load a couple of functions. So far, this is the script I'm using:

...
<head>
...
<script type="text/javascript">
window.onload=function(){
header();
alert("test");
}
</script>
</head>
...

Unfortunately, this only operates until the page has been fully loaded. Is there a trigger I can use before the page fully loads?

I tried unsuccessfully:

...
<head>
...
<script type="text/javascript">
header();
alert("test");
</script>
</head>
...

 

ahmedtheking




msg:3237809
 12:54 am on Jan 31, 2007 (gmt 0)

Can I ask why you want to run a script before the page loads?

StupidScript




msg:3237811
 12:54 am on Jan 31, 2007 (gmt 0)

Why was that unsuccessful? Did it depend on something in the body to have loaded before it could function. You'll notice that
alert("test"); function, alone, would work fine, so it's probably something in the header() function.
mrhoo




msg:3238441
 4:47 pm on Jan 31, 2007 (gmt 0)

You can run any code you like in a script in the head of the document while the document is loading- but it stops the download until your code returns.

You can't use dom objects or methods before the page loads, and you can't call functions, like 'head()', that haven't been defined yet.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved