一行代码实现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();
    }

转载于:https://www.cnblogs.com/Zting00/p/7497635.html

你可能感兴趣的:(一行代码实现F11的功能,即让浏览器窗口全屏)