HTML5進入全屏和退出全屏

wzm10455發表於2016-02-14

引用地址:http://www.cnblogs.com/kingwell/p/3706352.html


現在主流瀏覽器基本上實現了全屏效果,但是不同瀏覽器實現不一樣:

【進入和退出全屏】

// Webkit (works in Safari5.1 and Chrome 15)
element.webkitRequestFullScreen();
document.webkitCancelFullScreen();
 
// Firefox 10+
element.mozRequestFullScreen();
document.mozCancelFullScreen();
 
// W3C 提議
element.requestFullscreen();
document.exitFullscreen();

例項 

 //進入全屏
 function requestFullScreen() {
     var de = document.documentElement;
     if (de.requestFullscreen) {
         de.requestFullscreen();
     } else if (de.mozRequestFullScreen) {
         de.mozRequestFullScreen();
     } else if (de.webkitRequestFullScreen) {
         de.webkitRequestFullScreen();
     }
 }
 //退出全屏
 function exitFullscreen() {
     var de = document;
     if (de.exitFullscreen) {
         de.exitFullscreen();
     } else if (de.mozCancelFullScreen) {
         de.mozCancelFullScreen();
     } else if (de.webkitCancelFullScreen) {
         de.webkitCancelFullScreen();
     }
 }



相關文章