js实现F11全屏效果

提示

该事件只能从用户操作的事件触发,因为全屏后看不到地址栏,很容易做成欺骗性质的钓鱼网站

  1. 打开全屏:

        const docElm = document.documentElement;
        if (docElm.requestFullscreen) {  
            docElm.requestFullscreen();  
        }  
        else if (docElm.mozRequestFullScreen) {  
            docElm.mozRequestFullScreen();  
        }  
        else if (docElm.webkitRequestFullScreen) {  
            docElm.webkitRequestFullScreen();  
        }  
        else if (elem.msRequestFullscreen) {  
            elem.msRequestFullscreen();  
        } 
  2. 退出全屏:

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

miomiomio
147 声望5 粉丝

人生昧履,砥砺而行