Welcome to WebmasterWorld Guest from 54.167.0.111

Forum Moderators: open

Message Too Old, No Replies

Before onload

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

     

Jeremy_H

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

StupidScript

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

WebmasterWorld Senior Member 10+ Year Member



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

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

5+ Year Member



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.