« PREV: iMeet Custom Fan...
Borderless Brands... :NEXT »

wmode=opaque iframe using jquery

Fixing YouTube iFrame Z-index using jQuery

Are you tired of trying to find fixes for YouTube iFrame videos or other embedded iFrames overlapping parts of your website that won’t work in every browser(especially IE)? Sure there’s a simple fix by just adding “wmode=opaque” to the end of the source string but what if you have tons of videos already on your site? In this quick tutorial we will show you an easy way to automate the addition of “wmode=opaque”, using jQuery, to all embedded iFrames on your website. This will not only fix any new iFrame videos added to your website but all previous iFrame videos as well.

The jQuery Fix

Simply add this jQuery script inside the head tag of your website and you’re done:

<script type="text/javascript">
$(document).ready(function(){
    var frames = document.getElementsByTagName("iframe");
    for (var i = 0; i < frames.length; i++) {
        frames[i].src += "?wmode=opaque";
    }
});
</script>

Once added, test your website, your embedded iFrames should now never overlap any sections of your website that are using the z-index property.

Don’t Forget jQuery

This fix relies on the jQuery JavaScript library in order to function; you must either link directly to jQuery or download the latest version and upload it to your server. Here’s an example of ours located in our WordPress theme:

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.js">
</script>

Download jQuery

You can download the latest version of jQuery HERE.

Posted In

Tutorials

7 Comments

  1. Pingback: How to Stop YouTube Videos from overlapping the Social Toolbar | Social Toolbar Pro

  2. Pingback: 45 Highly Useful jQuery And JavaScript Tutorials

  3. Pingback: Highly Useful jQuery And JavaScript Tutorials

  4. Gerson May 10, 2012

    Thanks !
    The best and complete code:
    var frames = document.getElementsByTagName(“iframe”);
    for (var i = 0; i < frames.length; i++) {
    src = frames[i].src;
    if(src.indexOf('embed') != -1) {
    if(src.indexOf('?') != -1) {
    frames[i].src += "&wmode=transparent";
    }else{
    frames[i].src += "?wmode=transparent";
    }
    }
    }

    Reply
  5. Drew May 13, 2012

    It works great. But it has the bad side effect of messing up google ads. :(

    Reply
  6. bob April 11, 2013

    Hi, I put the gerson code at the end of my header and it seems to work perfectly ( no google ad problem on my site.

    Thanks a lot , this fix save me much much time.

    Reply

Leave a Reply

Your email is never published nor shared.
Required fields are marked *

You may use these HTML tags and attributes:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. Or subscribe without commenting.

 
Wacom Community Responsive Wordpress Customization | Daddy Design http://t.co/Qf7uaJemIe via @daddydesign1 day ago