How to add wmode=“transparent” for every flash object & ebmed tag?

后端 未结 6 726
無奈伤痛
無奈伤痛 2020-12-14 04:29

I have a page which displays dynamic flash content from issuu.com. I need to add wmode=\"transparent\" because otherwise navigation menu shows under flash. Is t

6条回答
  •  萌比男神i
    2020-12-14 05:16

    ok, after 2 days of searching the web for the answer i've found a pure JS function that fix it in all browsers!

    there you go:

    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(//i))
                    new_object = html.replace(//i, "");
                // add a new wmode parameter
                else
                    new_object = html.replace(/<\/object\>/i, "\n");
                // loop through each of the param tags
                var children = object.childNodes;
                for (j = 0; j < children.length; j++) {
                    try {
                        if (children[j] != null) {
                            var theName = children[j].getAttribute('name');
                            if (theName != null && theName.match(/flashvars/i)) {
                                new_object = new_object.replace(//i, "");
                            }
                        }
                    }
                    catch (err) {
                    }
                }
                // replace the old embed object with the fixed versiony
                object.insertAdjacentHTML('beforeBegin', new_object);
                object.parentNode.removeChild(object);
            }
        }
    }
    

    now you can just run in when the page loads with jQuery:

     $(document).ready(function () {
          fix_flash();
          // Call Function
     }); 
    

提交回复
热议问题