Welcome to WebmasterWorld Guest from 54.225.16.10

Forum Moderators: open

Message Too Old, No Replies

Before onload

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

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

Preferred Member

10+ Year Member

joined:Aug 12, 2005
posts:411
votes: 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>
...

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 12, 2004
posts: 789
votes: 0


Can I ask why you want to run a script before the page loads?
12:54 am on Jan 31, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 20, 2004
posts:1477
votes: 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.
4:47 pm on Jan 31, 2007 (gmt 0)

New User

10+ Year Member

joined:Feb 22, 2006
posts:24
votes: 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.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members