Quick Tip: Make Flash Play Nice With The DOM

Ever been working on a web application or site and encountered the nasty little issue of Flash floating over everything else?  No matter what you do to your markup or CSS, the Flash object just keeps appearing above everything in the page.  Forget about tweaking position properties or z-index values, it just won’t work.

The problem is often visible in blogs that embed YouTube videos and other Flash content.  Case in point, this recent post on TechCrunch.  When you mouse over any of the text links which spawn popup windows, you’ll notice the popups load under the embedded Flash video.  Very annoying.

So what’s the fix?  It’s really simple.  When embedding a Flash object, you have to add a “wmode” parameter.  After that, everything will work like a charm.

Let’s take a look at the source for the video which was embedded in the TechCrunch article.  Here’s what it looks like:

<object width="480" height="385">
  <param name="movie" value="http://www.youtube.com/v/IsV-lgnAjps&#038;hl=en&#038;fs=1&#038;"></param>
  <param name="allowFullScreen" value="true"></param>
  <param name="allowscriptaccess" value="always"></param>
  <embed src="http://www.youtube.com/v/IsV-lgnAjps&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed>
</object

The video will display fine with this code.  But when you want another element to appear above the Flash content, you’ll discover that it looks something like this:

screen_techcrunchmodalbroken

Add the wmode parameter and things begin to shape up.  Please note – you have to set wmode in TWO places; you have to add a new <param> tag and you also need to enter a wmode value in the <embed> tag.  The revised source with wmode set looks like this:

<object width="480" height="385">
  <param name="movie" value="http://www.youtube.com/v/IsV-lgnAjps&#038;hl=en&#038;fs=1&#038;"></param>
  <param name="allowFullScreen" value="true"></param>
  <param name="allowscriptaccess" value="always"></param>
  <param name="wmode" value="opaque"></param>
  <embed src="http://www.youtube.com/v/IsV-lgnAjps&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" width="480" height="385"></embed>
</object>

…and the output looks like this:

screen_techcrunchmodalfixed

As for why a popular tech site is pimping online dating profiles and free phones when they have absolutely nothing to do with the subject at hand, I’ll save that for another article on the problems plaguing online ad models.

Post to Twitter Tweet This Post to Yahoo Buzz Buzz This Post Post to Digg Digg This Post Post to Facebook Facebook Post to StumbleUpon Stumble This Post

1 Comment to Quick Tip: Make Flash Play Nice With The DOM

  1. November 7, 2009 at 10:27 pm | Permalink

    Hey just wanted to say thanks, I was having this exact problem with one of my clients flash widgets on their website. :) Saved me from modifying my CSS and saved tons of time.

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>