PDA

View Full Version : preload function in Javascript


joble
10-04-2002, 04:01 PM
Hi All,

I'm using the onload function in Javascript (see sample code below) but it looks like it executes after when the webpage is
completely loaded. Is there any function that will run prior to
onload() function or prior the webpage loading ?

<script language="javascript">
onload = function () {
.......
}
</script>


Thank you in advance.

Best regards, joble.

adios
10-04-2002, 04:23 PM
joble...

Hmm...you was expecting - onload to run - before the page was loaded? :p

Only kidding. Anyway: it's an event handler, not a function; you stick a function inside it, to be run when the actual event - a load event, in this instance - is fired. You can get any function to run before the page is loaded simply by calling it at the spot in the page where you'd care to have it run. HTML files are read from top-to-bottom, so, if you've taken care to define the function beforehand, simply citing its name (inside a script block) will run it immediately. A lot of <body> embedded scripts do this.

joble
10-04-2002, 04:39 PM
Hello,

Thanks a lot!!!

By the way, can you recommend websites for free
advance Javascript tutorial ? Thank you.

Best regards, joble.

adios
10-04-2002, 04:52 PM
Well, I'd recommend a book, but you might have to steal it (I think most places charge). The best freebie is probably Thau's JS toot at webmonkey (http://hotwired.lycos.com/webmonkey/98/03/index0a.html). It's also available in book form.

Best regards to you, too.