jQuery and SWFObject conflict

I experienced some strange behaviour today when building a site which was using jQuery and SWFObject. Our Flash files were loading ok and 99% of the javascript (using jQuery) was working fine.

The problem was found only in IE (sound familiar?) with the following code:

$(document).ready(function(){

	$('#submitButton').click(function(){

When the ‘submitButton’ was clicked, this function was not firing in IE. After some googling I found that there is a slight conflict with jQuery and SWFObject. I tested this and found the problem in jQuery 1.1.x and 1.2.1.

I found the fix on the SWFObject forums which is basically using jQuery to load the .swf:

<script type="text/javascript">
	$(document).ready(function(){
		var so = new SWFObject("movie.swf", "mymovie", "400", "100%", "8", "#336699");
		so.addParam("quality", "low");
		so.addParam("wmode", "transparent");
		so.addParam("salign", "t");
		so.write("flashcontent");
	});
</script>

All good in all browsers :)

Post a Comment or Leave a Trackback

9 Comments

  1. September 28, 2007 at 7:18 pm | Permalink

    if you’re using already jquery, then download the media plugin to write the flash for you.

    http://malsup.com/jquery/media/

  2. September 29, 2007 at 2:32 am | Permalink

    Hi Tony,

    The media plugin looks like it adds <object> and <embed> tags which are bad bad bad for many reasons, particularly the IE ‘click here to activate’ issue which happened when Microsoft lost the EOLAS court case a year ago.

    UFO quickly became the standard for embedding Flash, then SWFObject. The authors for both those methods are now working together on a new way to embed Flash etc which I believe doesn’t rely on javascript.

    Anyway, check out SWFObject for more info here: http://blog.deconcept.com/swfobject/

  3. September 29, 2007 at 10:29 am | Permalink

    Michael,

    Any JS plugin that manages media adds object/embed tags to the DOM. That exactly what happens when you execute this line in your code:

    so.write(“flashcontent”);

    The jQuery Media Plugin just makes working with media simpler and handles many, many media types beside Flash. It even uses SWFObject if that script is loaded.

    Cheers!

  4. September 29, 2007 at 11:41 am | Permalink

    @Malsup – Ohhh nice! I just read (a little further than before) up on the media plugin. Man it is nice.

    Thanks for the comment and the info, much appreciated :)

  5. jordan
    November 28, 2007 at 11:11 pm | Permalink

    ahhhhh. thanks for posting this. i was … losing it.

  6. December 17, 2007 at 4:04 pm | Permalink

    Thank you so much !

    I was searching a patch that make jquery and swfobject working together and yours is fantastic !

    (sorry for my english, i’m french geek girl)…

  7. December 18, 2007 at 4:11 am | Permalink

    @Jordan/@Aurore – Glad it helped :)

  8. Ale
    February 26, 2009 at 9:18 am | Permalink

    Hi Michael,
    sorry to borrow You but I see your post into TINY slideshow.

    Do You resolve the conflict with jquery core?

    Thanks
    Ale

  9. Jan Dantes
    April 16, 2010 at 11:22 am | Permalink

    Typeface.js(http://typeface.neocracy.org/) doesn’t load with SWFObject attached,
    but this solved the problem. Thank you so much!

One Trackback

  1. By SWFObject Conflicts Galore « Peng’s Blog on November 16, 2009 at 9:13 pm

    [...] conflict with JQuery [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*