136

Using javascript with jQuery, I am adding an iframe with a youtube url to display a video on a website however the embed code that gets loaded in the iframe from youtube doesnt have wmode="Opaque", therefore the modal boxes on the page are shown beneath the youtube video.

Any ideas how to solve the issue?

1
  • Is this still an issue? I used this solution before but cannot reproduce the original issue in the latest Chrome/Firefox/IE. Nov 18, 2013 at 17:03

9 Answers 9

239

Try adding ?wmode=opaque to the URL or &wmode=opaque if there already is a parameter.

If it doesn't work try this instead, &wmode=transparent which will work in IE browser as well.

8
  • 1
    nice! works on firefox & chrome but for some reason doesnt work on IE... any ideas ? Nov 24, 2010 at 13:10
  • 31
    try using &wmode=transparent instead
    – Shabith
    Nov 25, 2010 at 7:23
  • 29
    The "&wmode=xxxx" setting assumes that you're already passing parameters in the URL. I wasn't in my case, so I instead need to add "?wmode=xxxx" to the URL. May 27, 2011 at 20:29
  • 6
    Differences between opaque and transparent. opaque is supposed to be more performant.
    – donut
    Sep 14, 2011 at 17:36
  • 3
    Shabith - "wmode=Opaque" should be "wmode=opaque" (lowercase 'o')
    – John
    Mar 19, 2012 at 13:39
81

Try adding ?wmode=transparent to the end of the URL. Worked for me.

1
  • 'Transparent' should be the preferred option in my opinion.
    – Foxinni
    Oct 17, 2012 at 9:19
18

If you are using the new asynchronous API, you will need to add the parameter like so:

<!-- YOUTUBE -->
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
//    after the API code downloads.
var player;
var initialVideo = 'ApkM4t9L5jE'; // YOUR YOUTUBE VIDEO ID
function onYouTubePlayerAPIReady() {
    console.log("onYouTubePlayerAPIReady" + initialVideo);
    player = new YT.Player('player', {
      height: '381',
      width: '681',
      wmode: 'transparent', // SECRET SAUCE HERE
      videoId: initialVideo,      
       playerVars: { 'autoplay': 1, 'rel': 0, 'wmode':'transparent' },
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
}

This is based on the google documentation and example here: http://code.google.com/apis/youtube/iframe_api_reference.html

5
  • 7
    Note that this ALSO needs wmode in playerVars. When it's just under YT.Player, it will only work for the HTML5 player. Adding wmode to playerVars also sends that parameter to the Flash object, which has its own z-order problem. See here: groups.google.com/forum/?fromgroups#!topic/youtube-api-gdata/… I'll edit your answer accordingly. Mar 21, 2012 at 4:18
  • 1
    I tried this and it did not work. I also did not find any reference to wmode in YouTude documentation.
    – sboisse
    Oct 16, 2013 at 20:37
  • The link changed since I first posted, as did the method for setting the wmode. You can set any flash parameter now or youtube player parameter through playerVars. I have updated the above example. Oct 17, 2013 at 19:10
  • Loading a entire API just to change a value that can be easily changed in the URL is a total overkill. Don't use this.
    – fregante
    Nov 16, 2013 at 16:07
  • There are some of us who work with the chromeless player and already use the JS API for controlling the UI. For us, this solution totally rocks! Thanks
    – maxijb
    Jan 2, 2014 at 15:26
8

Adding ?wmode=opaque to the URL seems to solve this problem for me, although I have not tested it in IE yet.

For those of you having troubles with the previously proposed solution, note that an inital ampersand will only work if you are already supplying other arguments to the URL. The first argument must have an initial question mark: http://www.example.com?first=foo&second=bar

1
  • I was initially getting a black rectangle regardless of the video I was trying to show.. turned out the test machine didn't have flash installed and the dialogue for installing flash was offset too much!
    – Zeb
    Sep 16, 2011 at 12:44
3

Add &amp;wmode=transparent to the url and you're done, tested.

I use that technique in my own wordpress plugin YouTube shortcode

Check its source code if you encounter any issue.

1
  • Adding &amp;wmode=transparent after the you tube URL Solved the problem across all browsers. Thanks for Mr Tubal, Good job :)
    – user657543
    Mar 13, 2011 at 14:13
1

Just a tip!--make sure you up the z-index on the element you want to be over the embedded video. I added the wmode querystring, and it still didn't work...until I upped the z-index of the other element. :)

0

&wmode=opaque didn't work for me (chrome 10) but &amp;wmode=transparent cleared the issue right up.

0

I know this is an old question, but it still comes up in the top searches for this issue so I'm adding a new answer to help those looking for one for IE:

Adding &wmode=opaque to the end of the URL does NOT work in IE 10...

However, adding ?wmode=opaque does the trick!


Found this solution here: http://alamoxie.com/blog/web-design/stop-iframes-covering-site-elements

2
  • & and ? are both correct depending on which order they are used and which other settings are included in the URL. Obviously ? is used if this is the first (or only) setting, & otherwise.
    – Alex
    Sep 11, 2013 at 13:50
  • Yes, but IE has special needs. Just try it and see which works in IE 10 and which doesn't. I haven't tried this in IE 11 yet.
    – Amber June
    Dec 19, 2013 at 21:45
0

recently I saw that sometimes the flash player doesn't recognize &wmode=opaque, istead you should pass &WMode=opaque too (notice the uppercase).

Not the answer you're looking for? Browse other questions tagged or ask your own question.