2

I'm trying to make a YouTube video that is embedded as an iframe pop up in a modal window. I have it successfully working in Chrome and Firefox, but it will not work in IE. The Flash video seems to override the z-index, even though I have the wmode set to transparent (I've also tried opaque with the same results). Menus that pop over the video work correctly, but a div with an onclick event positioned directly over the video is not working. I've tried setting the z-index on just about every element manually, with no change.

I've included an HTML page that demonstrates the issue. On Chrome and Firefox if you click on the video, you will get an alert with a message of 'clicked', but this doesn't happen in IE.

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type='text/javascript'>
        $(function(){
            $("ul.dropdown li").hover(function(){
                $(this).addClass("hover");
                $('ul:first',this).css('visibility', 'visible');
            }, function(){
                $(this).removeClass("hover");
                $('ul:first',this).css('visibility', 'hidden');
            });

            $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
        });
    </script>
    <style type="text/css">
        *                                   { margin: 0; padding: 0; }
        body                                { font: 14px Helvetica, Sans-Serif; } 
        #page-wrap                          { width: 800px; margin: 80px auto; } 
        a                                   { text-decoration: none; }
        ul                                  { list-style: none; }
        p                                   { margin: 15px 0; }

        /* 
            LEVEL ONE
        */
        ul.dropdown                         { position: relative; }
        ul.dropdown li                      { font-weight: bold; float: left; zoom: 1; background: #ccc; }
        ul.dropdown a:hover                 { color: #000; }
        ul.dropdown a:active                { color: #ffa500; }
        ul.dropdown li a                    { display: block; padding: 4px 8px; border-right: 1px solid #333;
                                              color: #222; }
        ul.dropdown li:last-child a         { border-right: none; } /* Doesn't work in IE */
        ul.dropdown li.hover,
        ul.dropdown li:hover                { background: #F3D673; color: black; position: relative; }
        ul.dropdown li.hover a              { color: black; }


        /* 
            LEVEL TWO
        */
        ul.dropdown ul                      { width: 220px; visibility: hidden; position: absolute; top: 100%; left: 0; }
        ul.dropdown ul li                   { font-weight: normal; background: #f6f6f6; color: #000; 
                                              border-bottom: 1px solid #ccc; float: none; }

                                            /* IE 6 & 7 Needs Inline Block */
        ul.dropdown ul li a                 { border-right: none; width: 100%; display: inline-block; } 

        /* 
            LEVEL THREE
        */
        ul.dropdown ul ul                   { left: 100%; top: 0; }
        ul.dropdown li:hover > ul           { visibility: visible; }
    </style>
    <title>IE Bug</title>
</head>
<body>
<div class="page-wrapper">
    <div class="menu">
        <ul class="dropdown" style="z-index: 100;">
            <li>
                <a href="#">Menu</a>
                <ul class="sub_menu">
                    <li><a href="#">Sub Item 1</a></li>
                    <li><a href="#">Sub Item 2</a></li>
                </ul>
            </li>
        </ul>
    </div>
    <br />

    <div class="span4" style="background-color: transparent; display: block; margin-bottom: 0px; margin-left: 20px; margin-right: 0px; margin-top: 0px; width: 300px; z-index: 4;">
        <div class="column" style="margin-left: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; z-index: 3;">
            <div class="embedded-video" style="position: relative; z-index: 3;">
                <div class="video-launcher" onclick="alert('clicked');" style="position: absolute; cursor: pointer; width: 100%; height: 100%; z-index: 2;"></div>
                <div class="youtube-video" style="z-index: 1;">
                    <iframe style="z-index: 1;" width="300" height="225" src="http://www.youtube.com/embed/W8_Kfjo3VjU?rel=0&showinfo=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>
                </div>
            </div>
        </div>
    </div>

</div>
</body>

I've search all over trying to resolve this, but all I can find is information about setting the wmode and the z-index. There must be something else I'm missing, or maybe this just won't work in IE. Thanks for the help.

Brady
  • 212
  • 1
  • 8
  • Similar problem here: the flash object/swf with "wmode=opaque" worked fine in ie8, now in ie9 - the flash doesn't show any text. If wmode is changed to "window", flash will show text, but also the flash object is topmost and will cover other DOM elements. – scrat.squirrel Mar 09 '12 at 19:49

2 Answers2

1

You'll need to set the WMODE parameter to opaque inside any EMBED/OBJECT tags anywhere on any page regardless of where it is rendered -- on your page or in the IFRAME you're trying to show. Otherwise, the Flash player will be on top of everything (inherited or otherwise) no matter which of the pages (iframe or otherwise) rendered it out. It doens't matter that it isn't on your page. It's showing in the browser.

That can be problematic if you're showing another site's content on your site. Fortunately, YouTube has a solution:

Add ?wmode=transparent to the end of your YouTube URL in the IFRAME (or &wmode=transparent if you have a query string already). That worked perfect for me for modals.

Note: I came across this answer from another question and applied it to this one: https://stackoverflow.com/questions/8278390/how-can-i-make-iframe-respect-z-index-in-ie

Community
  • 1
  • 1
HBlackorby
  • 1,308
  • 1
  • 11
  • 18
  • Actually I am using the ?wmode=transparent query string and it still has this issue. If you look at my sample page you will see that this does allow a menu outside of the player to overlap the player, but a DIV the exact same size as the player will not capture the click event. – Brady Oct 12 '12 at 20:11
0

The only way I was able to make this work was to make the DIV larger than the embedded iFrame, so the DIV would capture the mouseover before the mouse passed over the iFrame. This is not a perfect solution as if the user moves the mouse fast enough it won't capture the mouseover.

This issue has been resolved in IE10.

Brady
  • 212
  • 1
  • 8