0

I think I may make mistakes on JS file but the console tells me no error. I got this problem after a small no-respond occured on my pc while I am writing on JS file.

It's a simplified version of my code so some names may be strange.But I try my best to reduce its length.

JS file includes click button event and full-screen video playing event .I get the function exitFullscreen() worked properly until this accident.Now I press 'F11' or 'Esc' the state recovers with nothing occured.

//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>
张绍峰
  • 301
  • 2
  • 13
  • It seems like you never call the function – Nora Sep 18 '16 at 08:35
  • Can not pressing 'F11' or ‘Esc’ call exitFullscreen() automatically?@Nora – 张绍峰 Sep 18 '16 at 08:48
  • You can bind to this event. You can read more about it [here](https://developer.mozilla.org/en-US/docs/Web/Events/keypress) and [here](https://api.jquery.com/keypress/) – Nora Sep 18 '16 at 09:42
  • I know how to bind ,I make the mistake of thinking that default exit method (such as pressing 'F11' or ‘Esc’)can also active the function exitFullscreen(). – 张绍峰 Sep 19 '16 at 03:47
  • Emm,it is still a problem.‘F11’ and 'Esc' are special,and you can not change the event.I test binding on other keys ,and they are OK.Also,I have try function preventDefault() to capture the key'F11' and ‘Esc’,but it doesn't work. – 张绍峰 Sep 19 '16 at 05:37

0 Answers0