代码之家  ›  专栏  ›  技术社区  ›  Simon

仍在使用jquery删除的DIV上播放的Flash视频(IE bug)

  •  14
  • Simon  · 技术社区  · 15 年前

    我有一些jquery标签,其中一个有一个flash视频。当我在一个选项卡中播放视频,并在FF或Safari中单击另一个选项卡时,视频会随着声音停止,单击返回到“视频”选项卡会按预期重新加载内容。

    在Internet Explorer中,情况并非如此,即使未选择选项卡,视频也会继续播放。我的理解是当 display:none (jquery hide())是应用的,DOM元素基本上从布局中删除了——为什么IE浏览器没有发生这种情况,我如何修复它?

    13 回复  |  直到 10 年前
        1
  •  22
  •   Marlon Creative    14 年前

    要删除视频并重新添加,请将以下内容添加到关闭视频窗口的功能中:

     // Remove and re-add video
     var clone = $("#video-holder").clone(true);
     $("#video-holder").remove();
     $("#video").html(clone);
    

    其中有一个环绕的“video”分区,在一个包含嵌入代码的“video holder”分区内。

        2
  •  6
  •   Divya Manian    15 年前

    当您从包含flash-like的DIV中切换开时,可以尝试删除元素。 $("object").remove();

        3
  •  3
  •   EdChum Arthur G    12 年前

    只需这样刷新:

    var a = document.getElementById('div_movie').innerHTML;
    document.getElementById('div_movie').innerHTML = a;
    
        4
  •  2
  •   Alex    14 年前

    $(“videocontainer”).html(“”);

    似乎是正确的答案,但如果我单击同一个元素两次,它将保持为空。

        5
  •  1
  •   BuKToP    15 年前

    只需像这样清除视频的容器:

    $(“videocontainer”).html(“”);

        6
  •  0
  •   Steerpike    15 年前

    很可能是因为你申请了 display: none; 指向持有闪光对象的DIV,而不是闪光对象本身。

    我今天也遇到了类似的问题,虽然我没有一个确切的解决方案,但当你在两个跳台之间跳来跳去尝试关闭播放器时,我确实有可能尝试一下:

    $(flashobjectid).attr('height', '0');
    

    如果您使用的Flash播放器恰好是常用的JW播放器,那么您可以这样做(隐藏DIV时):

    document.getElementById(playerId).sendEvent("PLAY","false"); 
    
        7
  •  0
  •   tahdhaze09    15 年前

    您可能需要编程A player.stop player.pause 上的播放器功能 onBlur 页面事件。

        8
  •  0
  •   Sudhir Jonathan    15 年前

    你能做的最有用的事情就是贴出你正在使用的视频播放器。YouTube和Brightcove都有JavaScript API,可以用来控制播放器。就像塔哈兹在这里说的,最好的方法是停止window.onblur事件中的玩家,当它获得焦点时重新启动。

    使用CSS阻止视频播放充其量是很棘手的,充其量是一个黑客…使用播放器附带的flash javascript桥接API。

        9
  •  0
  •   Gokhan Demirtas    15 年前
    $("#flashContainer").empty() 
    

    还将刷新嵌入代码并停止闪存

        10
  •  0
  •   Avatar    13 年前

    我们有同样的问题。Flash视频是使用swfobject.embedswf(…)嵌入的,但是,当使用jquery隐藏DIV时,IE9没有停止视频。

    简单工作: 再次调用swfobject.embedswf(…)以(重新)将swf加载到同一目标分区。

    如果你有自动播放的视频,在隐藏时尝试加载另一个空的SWF文件。 干杯

        11
  •  0
  •   Peter O. Manuel Pinto    12 年前

    我对嵌入的YouTube视频也有同样的问题。这是在IE、Firefox、Chrome和Safari中工作的最终解决方案:

    下面是jquery脚本、html和css,用于解决IE在隐藏嵌入的YouTube视频时继续播放声音的问题。

    这是jquery脚本(我将其放在结束body标记之前):

    <script type="text/javascript">
    $(function() {
    
        $('.close').click(function() {
    
        // needed to find some way to remove video and then replace it because IE would close the div but continue to play sound
    
    
        $('iframe').hide();   // must hide the YouTube iframe first or closing it before playing will cause a black window in IE
    
    
        $('#video1').hide('fast');  // then hide the container div that has the video div that has the YouTube iframe in it
    
        var bringback = $("#tinleyvideo").clone(true);   //clone the div that has the YouTube iframe and assign it to a variable
    
        $("#tinleyvideo").remove(); // remove the div that has the YouTube iframe
    
        $("#video1").html(bringback);   // replace or recreate the div that has the YouTube iframe using the variable with cloned information
        });
    
        $('.tourism').click(function() {
            $('iframe').show();   // show the YouTube iframe                         
             $('#video1').show('fast');   // show the div that contains the YouTube video div
        });
    }); 
    

    这是HTML结构。“旅游”类的链接标签是一个图像链接,用于显示视频弹出窗口。ID为“video1”的DIV标记是ID为“tinleyvideo”的DIV的容器DIV,其中包含YouTube嵌入的iframe代码。带有“close”类的链接标签使用jquery隐藏视频。

    <a href="#" class="tourism"><img src="images/home_video.jpg" width="217" height="161" border="0"/></a>
    
    
    <div id="video1">
           <div id="tinleyvideo"><a href="#" class="close" style='float:left; color:white; padding-bottom:10px; font-size:12px;'>Close</a><br />
    <iframe width="560" height="315" src="http://www.youtube.com/embed/XxnM7UzquSs?rel=0" frameborder="0" allowfullscreen></iframe>
        </div>
    </div>
    

    CSS(它定位弹出窗口,最初将其显示设置为“无”,并添加其他自定义样式):

    #video1  {
        position: absolute;
        top:240px;
        left:220px;
        width:560px;
        height:360px;
        display: none;
        -moz-border-radius: 10px; 
        padding: 10px; 
        background-color: #486A74; 
        border: 3px solid #DCC35C;
        z-index:400;
        }
    

    希望这有帮助。

        12
  •  0
  •   Aditya Jhunjhunwala SolidALb    11 年前

    我的解决方案,应该是这样的:

    $('#myVideoContainer object').remove();
    
        13
  •  0
  •   giacatho    10 年前

    不需要使用jquery,纯javascript解决方案就足够了。只需将player div替换为其自身的克隆:

    oldvideodiv=document.getElementByID(videoID);

    newvideodiv=oldvideodiv.clonenode(真);

    oldvideodiv.parentnode.replaceChild(newvideodiv,oldvideodiv);