View Full Version : window.onload not working in IE

02-27-2012, 12:33 PM

I have a bit of javascript that automatically loads Shadowbox on load.

It works perfectly in Firefox, Chrome but NOT IE.

If I put a standard link to open Shadowbox does work in IE, so it's not the shadowbox, it's definitely the window.onload bit which isn't working.

Here is my code.

<link rel="stylesheet" type="text/css" href="shadowbox/shadowbox.css">
<script type="text/javascript" src="shadowbox/shadowbox.js"></script>
<!--this bit is for a link to open the Shadowbox from a link elsewhere on the page -->
<script type="text/javascript">

<script type="text/javascript">
window.onload = function() {
content: 'flash/flash002.swf',
player: "swf",
title: 'Open Shadowbox',
width: 1200,
height: 800,




This DOES work though, so I know it's not the Shadowbox with the issue

<a href="flash/flash002.swf" rel="shadowbox;height=800px;width=1200px">Open Shadowbox</a>

Really appreciate your help!


02-27-2012, 01:36 PM
Why didn't you put the Shadowbox.init into the window.onload? I bet it would work then .. window.onload has been a well known standard for years, even for IE. So the problem cannot be related to window.onload

02-27-2012, 02:11 PM
Hi - Thanks for your reply.

I can add it but that code works in every other browser I can test in just as it is, so there is something different about IE. The code works ok otherwise.

Let me have a go and I'll let you know.


02-27-2012, 02:15 PM
Hi - I tried this and it didn't work.

Even if I put a really simple pop up into the window.onload it doesn't work either in IE - although it does in all other browsers.


02-27-2012, 02:18 PM
Hi - I've also run the code using the Error checker in Firefox which usually flags up any coding issues, no errors.

I've done some further testing - the issue is ONLY with IE9. IE8 works perfectly.

Just in case this helps isolate the issue.



02-27-2012, 02:26 PM
What is the !DOCTYPE of your document?

02-27-2012, 02:34 PM
It's strict.

Thanks again!


02-27-2012, 02:52 PM
As I don't have IE9, I am not able to test. window.onload works perfectly well on my IE8 and I never heard about problems with window.onload on IE9 ... maybe someone else can help?

02-27-2012, 02:54 PM
Thanks! It works fine in IE8 here too, how frustrating!!

Really appreciate your time! I found this:


Which suggests that maybe I need to use a slightly different way for IE9?


02-27-2012, 07:25 PM
Why not just put all that JavaScript at the bottom of the page (where JavaScript belongs) and where you don't need to test for the page having finished loading when all you need to know is that the HTML has loaded (which it will have if the script is at the bottom of the page).

02-27-2012, 07:43 PM
... except for the images and other binary content ... window.onload will also wait for those items to finish loading. Moving Javascript to the bottom of the page will not be equivalent to that.

02-27-2012, 09:26 PM
... except for the images and other binary content ... window.onload will also wait for those items to finish loading. Moving Javascript to the bottom of the page will not be equivalent to that.

Yes it will since browsers will not download JavaScript while other files are downloading. While browsers can download up to eight files at a time they doso aonly provided none of the files are JavaScript. When they get a request to download JavaScript they wait until after all the currently downloading files finsh downloading then download the JavaScript by itself and only when the Javascript finishes downloading will they resume downloading the other files eight at a time. So with the script at the bottom of the page it is almost certain that all the other files have already downloaded sine they will all have been requested first and the browser cannot start downloading the JavaScript until the files already downloading finish.

Only by adding an async attribute to the script tag will those few browsers that understand that attribute actually start downloading the JavaScript before all the other files finish downloading.