一行代码实现F11的功能,即让浏览器窗口全屏

1、全屏

//全屏
    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();
    }

2、退出全屏

    //W3C
    if (document.exitFullscreen) {
      document.exitFullscreen();
    }
    //FireFox
    else if (document.mozCancelFullScreen) {
      document.mozCancelFullScreen();
    }
    //Chrome等
    else if (document.webkitCancelFullScreen) {
      document.webkitCancelFullScreen();
    }
    //IE11
    else if (document.msExitFullscreen) {
      document.msExitFullscreen();
    }
posted @ 2017-04-07 15:35  ning0_o  阅读(1988)  评论(0编辑  收藏  举报