如何在更改页面事件中停止YouTube视频和音频播放

时间:2019-07-08 19:52:39

标签: javascript html

我的html中有2个单独的页面,均位于iframe中。导航首页,音乐等控制显示哪个帧。第一页(首页)iframe(ifr0和ifr1)指向具有嵌入式YouTube视频的vid.html。

第二页(ifr2)指向播放器应用程序player.html。页面(iframe)更改时如何停止播放视频和/或音频?

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Q_7-8_stackoverflow</title>
<link href="Q_7-8_stackoverflow.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
<!--
function show(which)
{
    for ( var n = 0; n < 999999; ++n )
    {
        var iframe = document.getElementById("ifr" + n);
        if ( iframe == null ) return; // no more to check
        iframe.style.display = ( which == n ) ? "block" : "none";
    }
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
//-->
</script>
</head>

<body>
<div id="layout">
	<div id="main">
		<iframe id="ifr0" src="vid_7-8.html" width="650" height="650" scrolling="no" frameBorder="0" style="display:block"></iframe>
		<iframe id="ifr1" src="vid_7-8.html" width="650" height="650" scrolling="no" frameBorder="0" style="display:block"></iframe>
		<iframe id="ifr2" src="player/player_7-8.html" width="650" height="650" scrolling="no" frameBorder="0" style="display:block"></iframe>
	</div>
	<div id = "navibar_jj">
		<div class="navbar">
  			<a href="#"onclick="show(1)">Home</a>
  			<a href="#"onclick="show(2)">Music</a>
  			<a href="#"onclick="show(3)">About Me</a>
		</div>
	</div>
</div>
</body>
</html>

0 个答案:

没有答案