Last week, I had a problem with flash object which is rendering dynamically on to my web pages. Actual scenario to explain about this issue is that – when I am trying to get some videos on my page the basic flash object tag is rendering automatically which has not got wmode=”transparent” set by default, with that other div containers are not showing up properly. Like for example the menu layer is going beyond the flash player that is video player which looks weird for the users who are viewing the page.
I tried couple of hours by appending respective param tag [] to the object tag using jQuery. Appending of param tag is fine but there is no change in the behavior of that object tag – since I am trying to append the tag without doing any cloning method. I mean, once after appending the param tag to the object the respective object tag should be refreshed to make that flash object tag to work. The option which I am trying was not working properly.
Either we can try with two scenario’s here:
1. While retrieving the flash object tag, with jQuery check whether you have with the Object tag – if you could not find the same, then append the respective param tag and then put it on to your page.
2. The second scenario would be, after rendering the Object tag check for the param tag – if you could not find append the same and try to clone it and refresh the object tag accordingly using jQuery.
After searching for hours I could find two references from two different websites. One came up with native JavaScript function code and the other with jQuery code.
jQuery Code:
Key feature about this is that, just include the script in any webpage, it will change/add the wmode to transparent to embed or Object tags accordingly. Content Courtesy: Jose, you can download the js from nobilesoft.com – https://www.nobilesoft.com/Scripts/fix_wmode2transparent_swf.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
/* Wrote by Free to use for any purpose Tested at IE 7, IE 8, FF 3.5.5, Chrome 3, Safari 4, Opera 10 Tested with Object[classid and codebase] < embed >, object[classid and codebase], embed, object < embed > -> Vimeo/Youtube Videos Please, reporte me any error / issue */ function LJQ() { var sc=document.createElement('script'); sc.type='text/javascript'; sc.src='https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'; sc.id = 'script1'; sc.defer = 'defer'; document.getElementsByTagName('head')[0].appendChild(sc); window.noConflict = true; window.fix_wmode2transparent_swf(); } if(typeof (jQuery) == "undefined") { if (window.addEventListener) { window.addEventListener('load', LJQ, false); } else if (window.attachEvent) { window.attachEvent('onload', LJQ); } } else { // JQuery is already included window.noConflict = false; window.setTimeout('window.fix_wmode2transparent_swf()', 200); } window.fix_wmode2transparent_swf = function () { if(typeof (jQuery) == "undefined") { window.setTimeout('window.fix_wmode2transparent_swf()', 200); return; } if(window.noConflict)jQuery.noConflict(); // For embed jQuery("embed").each(function(i) { var elClone = this.cloneNode(true); elClone.setAttribute("WMode", "Transparent"); jQuery(this).before(elClone); jQuery(this).remove(); }); // For object and/or embed into objects jQuery("object").each(function (i, v) { var elEmbed = jQuery(this).children("embed"); if(typeof (elEmbed.get(0)) != "undefined") { if(typeof (elEmbed.get(0).outerHTML) != "undefined") { elEmbed.attr("wmode", "transparent"); jQuery(this.outerHTML).insertAfter(this); jQuery(this).remove(); } return true; } var algo = this.attributes; var str_tag = ''; jQuery(str_tag).insertAfter(this); jQuery(this).remove(); }); } |
Native JavaScript Code:
Website: https://www.onlineaspect.com/2009/08/13/javascript_to_fix_wmode_parameters/
HTML Sample
1 2 3 4 5 |
<object width="200" height="300" data="example.swf" type="application/x-shockwave-flash"> <param name="quality" value="high" /> <param name="wmode" value="transparent" /> <param name="src" value="example.swf" /> </object> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
function fix_flash() { // loop through every embed tag on the site var embeds = document.getElementsByTagName('embed'); for(i=0; i<embeds.length; i++) { embed = embeds[i]; var new_embed; // everything but Firefox & Konqueror if(embed.outerHTML) { var html = embed.outerHTML; // replace an existing wmode parameter if(html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i)) new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i,"wmode='transparent'"); // add a new wmode parameter else new_embed = html.replace(/ |
1 2 3 |
$(document).ready(function () { fix_flash(); } |
This article might help most of the developers who has faced or trying to fix the problem of wmode=”transparent”.
Related Entries...
-
I would like to share one of the best video which depicts about the Entrepreneurship, this video show ...
-
The Sprite class is new in ActionScript 3.0, This class is a basic display list building block, which ...
-
Introduction Creating a nice and awesome enough Photo Gallery using
-
Introduction As we all aware that Firebug is one of the best and awesome tool to test or debug the w ...
-
Introduction: What is Google Wave? As the name depicts Wave is a communication channel between each ...
-
I think it was a great day for the people who were expecting Google to introduce Video and Voice Chat ...
-
Introduction: Below is the simple Bookmark script, which has been implemented using jQuery, this mig ...
-
John Resig, has explained us a better and interesting way of Method Overloading. Here he has discusse ...
-
This article will help beginners, that is who are new to jQuery and want to learn some tricks about j ...
-
This article will helps you to understand on how you can increase and decrease font-size of the conte ...
7 Responses
[...] How to: Add wmode=”transparent” for flash object using jQuery and … [...]
I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time & work.
found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later
Jose is 100% awesome! Really helpful code.
I tried but the vedio is disppeared now. It kust blink and then gone in IE7. is created after the embed object in IE7.
Thanks for this, very helpful script, saved me some hours of manually editing certain posts in wordpress. If anyone else stumbles into this post and needs a wordpress solution for this “css menu problem” with iframes, one can do the following:
Add the code below to your “functions.php” file
//Embed Video Fix
function add_video_wmode_transparent($html) {
if (strpos($html, “
add_filter('the_content', 'add_video_wmode_transparent', 10); // menu overlaps top videos
[...] https://developersnippets.com/2010/12/04/how-to-add-wmodetransparent-for-flash-object-using-jquer… [...]