If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

IE window.onload firing too early!! before page completely loads

There wasn't a plain javascript forums so I figured this to be the most appropriate place for this thread.

I have a page that runs a script on the window.onload event. My problem is that when the page is viewed in IE (6,7 & 8, have not checked other versions) a javascript error is thrown due to an element on the page not being loaded yet... and also... this does not happen when the page is first loaded but only on post backs and any time the page is loaded (after the very first load) unless you refresh (navigating back to the page without refresh throws the javascript error).

When you first load the page in IE it will load correctly. If you click on the URL and then press Enter to reload the page w/o refreshing, you will see the error I'm talking about. You can also see the error by pressing the "Post Back" button on the page.

You can scroll to line 341 on the page to see the window.onload script that calls each function. The error is occuring within the InitWorkArea() function called by InitApp(). Both of these functions are contained within the script file @ http://www.enterprisesofcbg.com/erp/scripts/globals.js. If you try to call the function manually by typing "javascript:InitWorkArea();" into the URL bar once the page has loaded it runs completely fine!?!?!

I hope this is all clear. I am pretty familure w/ client/server systems as I have been developing them since 2001.

Re: IE window.onload firing too early!! before page completely loads

Hey Danny, thanks for the reply. My problem is that the window.onload event is supposed to fire after the document, its images, scripts, styles, and all other refrenced files are completely loaded on the client's machine. So it's supposed to do exactly what you're describing... it just isn't.

I've used this same exact approach for years and for this is the first time this has ever happened.

Something on the page is causing the onload event to fire before specific elements on the page are loaded. You can see because when the error dialog pops up there are several placeholders on the document where content has not been fully loaded.

Re: IE window.onload firing too early!! before page completely loads

well window.addEventListener only works in FireFox and my problem is with the IE browser.

right now I already am attaching to the onload event with window.onload (IEs event subscription counterpart). I have also attached to the window.addEventListener on local tests although it cant be seen on the site posted above.

The script is currently running to attach to the event at the bottom of the page within the <body> tag. If I move it around it makes no difference (according to local tests). It's placed at the bottom of the page in the posted example because I was thinking that since the problem is that the event is firing before the page actually loads then placing the code that attaches to the event at the bottom of the page would ensure that atleast the html objects have been initiated when the event is triggered but even that doesnt work.

I am subscribing to the event like I have done a thousand times before. For some reason it doesn't work this time... I have other examples of this same protocal published & running right now w/o any problems.

Re: IE window.onload firing too early!! before page completely loads

Just so everyone knows, if you want to run local tests on your own all the script, css & image references contain the full virtual path so you can view the source and save it as html file on your local machine. Then you can modify it w/ text editor and run the file in your browser.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.