Element.requestFullscreen()方法

亲测

IE浏览器仅 IE11 支持

document.getElementById("fullScreen").onclick = function() {
        if (document.documentElement.RequestFullScreen) {
            document.documentElement.RequestFullScreen();
        }
        //兼容火狐
        console.log(document.documentElement.msRequestFullscreen)
        if (document.documentElement.mozRequestFullScreen) {
            console.log('火狐')
            document.documentElement.mozRequestFullScreen();
        }
        //兼容谷歌等可以webkitRequestFullScreen也可以webkitRequestFullscreen
        if (document.documentElement.webkitRequestFullScreen) {
            console.log('谷歌')
            document.documentElement.webkitRequestFullScreen();
        }
        //兼容IE,只能写msRequestFullscreen
        if (document.documentElement.msRequestFullscreen) {
            console.log('ie')
            document.documentElement.msRequestFullscreen();
        }
    }
    document.getElementById("fullScreenNormal").onclick = function() {
        if (document.exitFullScreen) {
            document.exitFullscreen()
        }
        //兼容火狐
        console.log(document.mozExitFullScreen)
        if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen()
        }
        //兼容谷歌等
        if (document.webkitExitFullscreen) {
            document.webkitExitFullscreen()
        }
        //兼容IE
        if (document.msExitFullscreen) {
            document.msExitFullscreen()
        }
    }

【参考链接】

posted @ 2018-09-14 14:10  卑面派对  阅读(943)  评论(0编辑  收藏  举报