ponedeljek, 27. september 2010

Kako preprečiti, da flash ne prekiva HTML vsebin

Pred časom sem naletel na težavo, ko je flash prekrival content. 

 

Kaj storiti? Ker je lahko flash dodan dinamično preko CMS-ja, je potrebno na clientu dodat atrubute wmode= transparent. Sliši se preprosto, a ponavadi ni, različni browserji in različne situacije.

 

Na koncu se je najbolje obnesla takale rešitev. Ne sicer dobesedna, a ideja je vzeta od tukaj:

 

 

 

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 = '< algo.length; i++) str_tag += algo[i].name + '="' + algo[i].value + '" ';         str_tag += '>'; var flag = false; jQuery(this).children().each(function (elem) { if(this.nodeName == "PARAM") { if (this.name == "wmode") { flag=true; str_tag += '';                 } else  str_tag += ''; } }); if(!flag) str_tag += '';                 str_tag += ''; jQuery(str_tag).insertAfter(this); jQuery(this).remove();         }); }

Celoten članek si lahko preberete tukaj, celotno kodo pa tukaj

Ni komentarjev: