Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Flash elements over CSS menu

Sometimes when you have CSS based navigation, it just doesn't work right with embedded flash elements.

To fix this, all you have to do is to set attribute wmode to transparent. But what if you have a CMS, where you can't control user input and you can't ask users to modify code. Then this function will help:

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(/wmodes*=s*('|")[a-zA-Z]+('|")/i))
            new_embed = html.replace(/wmodes*=s*('|")window('|")/i
                        ,"wmode='transparent'");
            // add a new wmode parameter
            else 
            new_embed = html.replace(/<embeds/i,"<embed wmode='transparent' ");
            // replace the old embed object with the fixed version
            embed.insertAdjacentHTML('beforeBegin',new_embed);
            embed.parentNode.removeChild(embed);
        } else {
            // cloneNode is buggy in some versions of Safari & Opera, but works fine in FF
            new_embed = embed.cloneNode(true);
            if(!new_embed.getAttribute('wmode') || 
                new_embed.getAttribute('wmode').toLowerCase()=='window')
                new_embed.setAttribute('wmode','transparent');
            embed.parentNode.replaceChild(new_embed,embed);
        }
    }
}

It goes through every embed element and sets attribute wmode to transparent. Just add it to onload event.


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus