SWFObject and IE6 causing hair-pulling agony
- by Piet
I recently used SWFObject to display a flash header on a website. I chose SWFObject because:
Instead of displaying an annoying ‘Install flash now’ message, it claims to be able to show alternate content. In this case: the original header image.
It claims to be compatible with more or less every browser out there.
Implementation went fine, until someone tested it on IE6 and got the following error:
Internet explorer cannot open the Internet site http://www…..
Operation aborted
Which basically means that the site just can’t be visited with IE6 (still used a lot in business environments), it even seems as if there’s something wrong with your internet connection.
Now, since about 10% of visitors to this site are still using IE6 (why does everyone still use Internet Explorer ???? Do YOU know that these days most people do NOT use Internet Explorer anymore ?)
Now after some googling, I found the suggestion to defer loading of the SWFObject.js as follows:
<script type="text/javascript" defer=”defer” src=”http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js”
</script>
<script type=”text/javascript” defer=”defer”
swfobject.registerObject(”myId”, “9″, “”);
</script>
What this does according to W3C: When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no “document.write” in javascript) and thus, the user agent can continue parsing and rendering.
I don’t know exactly why, but: HURRAY! It works now!!! Only… IE6 and IE7 (didn’t try IE8) now gave the following error:
Line: 19
Char: 1
Error: ’swfobject’ is undefined
Code: 0
URL: http://www…
But the flash was still running fine. Still, such an error isn’t clean, especially since almost half of the site’s visitors are using one of these Internet Explorer versions.
Now, wanting a quick fix I decided to do the following:
<script type="text/javascript" defer="defer"
if (typeof(swfobject) != "undefined")
swfobject.registerObject("myId", "9", "");
</script>
I admit this is a bit of a weird ‘fix’. You’d suspect the flash to stop working on IE6/IE7, which it doesn’t. Not planning on diving into it’s inner bowels, I regard this a ‘mission accomplished’ until someone somewhere posts a better solution (for which I setup some Google alerts).
Do you have a better solution?
What would be the impact on the webdev economy (or your life) if all browsers were compatible?
Addendum
Because the above turned out not to work with the new Firefox 3.5.3 (strangely, was OK with 3.5.2 when I tested it) I decided to cut the crap and use the ‘Dynamic Publishing’ way. Ok, so it won’t work for people who have javascript disabled, but who on earth would have flash installed AND javascript disabled?
To avoid the IE6 error with the ‘Dynamic Publishing’ way, I call swfobject.embedSWF right after the div that will be replaced with the flash content. Calling swfobject.embedSWF in the <head> would otherwise give me the above error in IE6 again.