SWFObject not embedding Flash in Firefox

Whilst working on a site that used SWFObject to add Flash to a page, I came across a situation where my Flash movie wouldn’t embed in Firefox, but it would in all the other browsers. Here’s an code excerpt from the page.

1
2
3
4
5
6
7
<script type="text/javascript">
   swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");
</script>
 
<div id="myContent">
   <p>Alternative content</p>
</div>

After spending around an hour on extensive research (Google!) and checking the case of my code, I still couldn’t find a solution to the problem.

Eventually I discovered that Firefox executes JavaScript at a different time to other browsers. Other browsers appear to load the page and then execute the JavaScript on the page, whereas Firefox appears to execute the JavaScript when it gets to it.  So by moving the script to below the div it miraculously worked in Firefox. It would probably be better if the embedSWF function was called on document ready. You can see the corrected code below. It’s so simple when you know how!

1
2
3
4
5
6
7
<div id="myContent">
   <p>Alternative content</p>
</div>
 
<script type="text/javascript">
   swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");
</script>
Posted by Mark on November 20th, 2009
 

2 Responses to “SWFObject not embedding Flash in Firefox”

  • Sam Says:

    We had a similar problem with our flash content not displaying in Firefox (and some versions of IE), the issue ended up being with Apache and mod_deflate, we added the following line:

    “SetEnvIfNoCase Request_URI \\.(?:swf)$ no-gzip dont-vary”

    and it it fixed it for us. Hope this helps somebody else because it had us going for a while.

  • Mark Says:

    @sam Thanks for the tip Sam! I’m sure it’ll save someone else a few hours of grief!

Leave a Reply