I have a script running that includes this statement:
if (!window.isLoaded) {
window.addEventListener("load", function() {
threeSixty.init();
}, false);
}
The script works fine everywhere except in good old Internet Explorer. The IE error message points to the ‘if’ statement above.
I’m reading that IE does not play nice with addEventListener and needs to be adjusted with perhaps ‘attachEvent’ to accomodate IE.
I’m reading and tinkering but can’t seem to get it sorted.
Does anyone have any idea how to get this to play nice with IE?
Thanks for any input!
The best way in your situation is to not use the load event at all. Just put your script tag at the end of the body, and you won’t need to deal with onload situations.
With very few exceptions all JavaScript should be attached at the bottom of the web page and not test for the load event.
The only time a script needs to test for the load event is if it is testing if all the images and/or other files have actually loaded in order to do something else if any didn’t load.
The only time a script shouldn’t be attached at the very bottom of the page is where it is making a decision on whether to display the page at all or to instead load another page (or reload the same page outside a frame).
I’m not sure that my page isn’t doing what you just described as the exceptions.
We took a CAD 360 interactive view and exported it into a webpage.
It’s actually a bunch of individual jpgs that are utilized in sort of a flip-book effect.
If the script is simply using the images and isn’t going to do something different if they are not there then it doesn’t really need to test if all the images have loaded before it starts.
Just for the record, (and not to dismiss the onload issue), as I tiptoe warily betwixt the legs of JS colossi I thought I’d mention that IE8 and under don’t support addEventListener, but there is a function that is designed to help IE along: