我想我可能会在JS文件上犯错,但控制台告诉我没有错误。 我在写JS文件时,在我的电脑上发生了一次小的无响应后,我遇到了这个问题。
它是我的代码的简化版本,所以有些名字可能很奇怪。但我尽量减少它的长度。
JS文件包括点击按钮事件和全屏视频播放事件。我得到函数exitFullscreen()正常工作,直到发生此事故。现在我按下F11'或者' Esc' 国家恢复没有任何结果。
//btnBeginClickEvent
function btnBeginClickEvent()
{
//hide button
this.style.display = "none";
this.style.visibility = "hidden";
//fullscreen and play
doPlaySequence();
}
/*playSequence*/
function doPlaySequence()
{
var divcontainer = document.createElement("div");
divcontainer.setAttribute("id","divop");
document.body.appendChild(divcontainer);
var playID = "op0";
var opplay = document.createElement('video');
opplay.setAttribute("id",playID);
opplay.preload = "none";
divcontainer.appendChild(opplay);
opplay.src = "http://www.w3school.com.cn/example/html5/mov_bbb.mp4";
var myPlayer;
myPlayer = videojs(opplay);
launchFullscreen(myPlayer);
myPlayer.play();
}
/*fullscreen*/
function launchFullscreen(element)
{
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.msRequestFullscreen){
element.msRequestFullscreen();
} else if(element.oRequestFullscreen){
element.oRequestFullscreen();
}
else if(element.webkitRequestFullscreen)
{
element.webkitRequestFullScreen();
}
else
{
}
}
//this function doesn't be called and the string "why" is never printed
function exitFullscreen()
{
console.log("why");//this one doesn't appeared now
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.oRequestFullscreen){
document.oCancelFullScreen();
}else if (document.webkitExitFullscreen){
document.webkitExitFullscreen();
}else{
}
}
/*global variables*/
$(window).load(function()
{
var btnBegin = document.getElementById("btnBegin");
btnBegin.addEventListener('click',btnBeginClickEvent);
});

/* san9op html noscroll and fullwindow */
.htmlset
{
overflow:hidden;
}
#btnBegin
{
position: fixed;
top: 50%;
left: 50%;
margin-top: -2em;
margin-left: -4em;
width: 8em;
height: 4em;
border-radius: 1em;
display: inline-block;
text-align: center;
text-decoration: none;
border:solid #69AA00;
}
u
{
color: blue;
font-size: 120%;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html class= 'htmlset'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<link href="../CSS/noscroll.css" rel="stylesheet">
<link href="https://vjs.zencdn.net/5.8/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/5.8/video.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
<script type="text/javascript" src="../js/op/opnew2.js"></script>
</head>
<body >
<button id ="btnBegin" type = "button"><U>Begin!</U></button>
</body>
</html>
&#13;