0

我编写了一些 JavaScript,当有人点击图片时会显示视频,然后他们可以点击“x”关闭视频,但视频在隐藏时继续在 ie8 中播放,但在 FireFox 和 Chrome 中停止。如果有人可以告诉我如何通过在单击“xbutton”图像时停止视频来解决此问题,我将不胜感激我已经为此奋斗了几个小时。这就是我对 JavaScript 所拥有的:

    function toggle(div_id) {
       var el = document.getElementById(div_id);
       if ( el.style.display == 'none' ) {  el.style.display = 'block';}
       else {el.style.display = 'none';}    }

    function blanket_size(popUpDivVar) {
      var blanket = document.getElementById('blanket');
      blanket_height = document.body.parentNode.scrollHeight;           
      blanket.style.height = blanket_height + 'px'; 
          }

    function popup(windowname) {
       blanket_size(windowname);    
       toggle('blanket');
       toggle(windowname);  
           }

这是我正在使用的 html。我只是使用dreamweaver 从我的计算机中添加一个.flv 视频文件。

    <div id="blanket" style="display:none;"></div>
    <div id="popUpDiv" style="display:none;">
    <a href="#popUpDiv" onclick="popup('popUpDiv')"><img 
    src="../New images/newxbtn-red.png" class ="xbutton" alt = "Close"/></a>
    <p> Video Header</p>
    <!--Dreamweaver video code starts here -->
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="622"
    height="350" id="FLVPlayer">
    <param name="movie" value="FLVPlayer_Progressive.swf" />
    <param name="quality" value="high" />
    <param name="wmode" value="opaque" />
    <param name="scale" value="noscale" />
    <param name="salign" value="lt" />
    <param name="allowScriptAccess" value="always" />
    <param name="FlashVars" 
    value="&amp;MM_ComponentVersion=1&amp;skinName=Halo_Skin_3&amp;streamName=video/bf-
    eng&amp;autoPlay=true&amp;autoRewind=false" />
    <param name="swfversion" value="8,0,0,0" />
    <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download 
    the latest version of Flash Player. Delete it if you don’t want users to see the 
    prompt. -->
    <param name="expressinstall" value="Scripts/expressInstall.swf" />
     <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
     <!--[if !IE]>-->
     <object type="application/x-shockwave-flash" data="FLVPlayer_Progressive.swf"  
     width="622" height="350">
     <!--<![endif]-->
    <param name="quality" value="high" />
    <param name="wmode" value="opaque" />
    <param name="scale" value="noscale" />
    <param name="salign" value="lt" />
    <param name="allowScriptAccess" value="always" />
    <param name="FlashVars"  
    value="&amp;MM_ComponentVersion=1&amp;skinName=Halo_Skin_3&amp;streamName=video/bf-  
    eng&amp;autoPlay=true&amp;autoRewind=false" />
    <param name="swfversion" value="8,0,0,0" />
    <param name="expressinstall" value="Scripts/expressInstall.swf" />
    <!-- The browser displays the following alternative content for users with Flash 
    Player 
    6.0 and older. -->'
    <div>
   <p><a href="http://www.adobe.com/go/getflashplayer"><img 
   src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"  
   alt="Get Adobe Flash player" /></a></p>
   </div>
   <!--[if !IE]>-->   
   </object>
   <!--<![endif]-->
   </object>
    <!-- Video Ends -->
     </div>
     <div class ="image">   
     <a href="#popUpDiv" onclick="popup('popUpDiv')">
     <img src="img/farmers/Donahue_Beef.jpg" width="190" height="110" alt="Beef" />
     <img src="../New images/playbtn.png" width="200" height="116" alt="Play" class = 
     "play"/></a>
     </div>

再次感谢!

4

2 回答 2

3

使用 jQuery 可能有一个非常简单的方法。在我的例子中,我生成了一个 Flash embed div,其中包含对象。使用 jQuery,您可以轻松地定义一个带有empty()单击功能的关闭按钮。这会清除 div 的内容,并且视频不再在 DOM 中。

$("#video a.close").click(function(){
 $("#flashlayer").empty();
}
于 2012-12-06T19:01:22.227 回答
1

首先,你必须在你的元素上监听click事件(我建议添加一个 ID):xbutton

function listen(event, elem, func) {
  if (elem.addEventListener) {
    elem.addEventListener(event, func, false);
  } else if (elem.attachEvent) {
    elem.attachEvent(event, func);
  }
}

listen('load', window, function() {
  var xbutton = document.getElementById('xbutton');
  var player = document.getElementById('FLVPlayer');
  listen('click', xbutton, function(e) {
    player.Stop();
    e.preventDefault();
  });
});

您可以使用 JavaScript 方法Stop()来停止您的 Flash 视频。

于 2012-03-19T20:05:34.800 回答