JavaScript Hack to Fix WMode=Transparent

I spent a couple hours over the last few days trying to add a parameter to a Flash object that I don’t have control over (the code and the video is hosted on another site). The website that I was working on had dropdown menus above the video, so I needed some way add the wmode parameter and set it to “transparent” since that fixes the z-index issue with Flash objects displaying over HTML objects.

Josh Fraser came up with a way of adding the wmode parameter to all Flash objects back in 2009, but I was still running into issues with his code in IE6 and IE9.

After trying to fix the issue in his code, I tried looking for support from Sorenson Media, the company that’s hosting the video, and I found a post that said it cannot be done. Earlier this week, I tried hosting their code locally and I was able to add the parameter then, but I wasn’t able to rely on their content management system to update the video content.

I finally thought of a really big hack to fix the problem. Sorenson Media’s code generates the HTML code in the JavaScript variable embedCode. I decided to make embedCode a global variable, then run Sorenson’s hosted code, and finally add the wmode parameter to my (now) global variable embedCode.

<script type="text/javascript">var embedCode = "";</script>
<script type="text/javascript" src="[hosted by Sorenson]/embedfl.js"></script>
<script type="text/javascript">
try {
embedCode = embedCode.replace("</object>","<param value='transparent' name='wmode'></object>");
document.getElementById("[Sorenson ID]").innerHTML = embedCode;
} catch(Err) {}
</script>

I know it’s not an elegant solution by any means, but at least it gets the job done. If anyone has other suggestions on how to fix this in a bunch of browsers (IE6-9, Firefox, Safari, and Chrome), please let me know.

Did you like what you just read?

Get updates sent directly to your inbox.

Corey Docken

Corey Docken

Corey is a designer and developer with over 10 years of experience building websites. He currently lives in southeastern Minnesota in a small town outside of Winona, MN.

Published on Thursday, January 13th, 2011 at 5:37 PM.
Last updated on Thursday, February 12th, 2015 at 5:38 PM.