js全屏与退出全屏

function Fullscreen() {
    var elem = document.documentElement;
    // 判断浏览器设备类型
    if (elem.webkitRequestFullScreen) {  // 兼容谷歌
        elem.webkitRequestFullScreen();
    } else if (elem.mozRequestFullScreen) {  // 兼容火狐
        elem.mozRequestFullScreen();
    } else if (elem.requestFullscreen) {
        elem.requestFullscreen();
    } else if (element.msRequestFullscreen) {  // 兼容IE
        elem.msRequestFullscreen();
    } else {
        //浏览器不支持全屏API或已被禁用
    }
}

// 退出全屏在谷歌浏览器无效
function ExitFullscreen() {
    if (document.exitFullscreen) {
        document.exitFullscreen();
    } else if (document.msExitFullscreen) {
        document.msExitFullscreen();
    } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
    }
}

 

posted @ 2021-08-14 09:54  ꧁执笔小白꧂  阅读(100)  评论(0编辑  收藏  举报