IF Javascript Not Loaded Yet

Is it possible to tell a javascript script to do something else if the page has yet to load completely or the included javascript file has yet to load?

Thanks
Ryan

Yes you can do something else if the whole page hasn’t loaded yet. Simply test using document.getElementById() for a particular id in the page exysts. If it does then that part of the page has loaded and if it doesn’t it hasn’t.

You can do the same with regards code in Javascript that may or may not have loaded by testing if a function in that script exists yet or not.

How appropriate is it to have the document load set a global variable, so that you can check for that instead?

Thanks and thanks. I think I’m going to test against first response, since the script uses a hidden iframe on bottom of page that does have an ID. If that is loaded, than the page is usually completely loaded.

Cheers
Ryan

The other option if you don’t want the JavaScript to run until the page has completely loaded is to place it immediately before the </body> tag where it is the last part of the page to load.