铭哥和佩佩的博客

铭哥和佩佩的博客分享Python、PHP、JavaScript、HTML5、CSS3等各种知识

JavaScript控制浏览器全屏和退出全屏

进入全屏

var docElm = document.documentElement;
//W3C  
if (docElm.requestFullscreen) {  
    docElm.requestFullscreen();  
}
//FireFox  
else if (docElm.mozRequestFullScreen) {  
    docElm.mozRequestFullScreen();  
}
//Chrome等  
else if (docElm.webkitRequestFullScreen) {  
    docElm.webkitRequestFullScreen();  
}
//IE11
else if (elem.msRequestFullscreen) {
  elem.msRequestFullscreen();
}

退出全屏

if (document.exitFullscreen) {  
    document.exitFullscreen();  
}  
else if (document.mozCancelFullScreen) {  
    document.mozCancelFullScreen();  
}  
else if (document.webkitCancelFullScreen) {  
    document.webkitCancelFullScreen();  
}
else if (document.msExitFullscreen) {
      document.msExitFullscreen();
}

添加新评论