js控制全屏显示

<button  id="fullBtn">点我全屏</button>
<iframe id="map" src="" style="width: 100%;height: 100%;"></iframe>

js

<script">
    var fullscreen = false;
    let btn = document.getElementById('fullBtn');
    let fullarea = document.getElementById('map')
    btn.addEventListener('click',function(){
        if (fullscreen) {    // 退出全屏
            if (document.exitFullscreen) {
                document.exitFullscreen();
            } else if (document.webkitCancelFullScreen) {
                document.webkitCancelFullScreen();
            } else if (document.mozCancelFullScreen) {
                document.mozCancelFullScreen();
            } else if (document.msExitFullscreen) {
                document.msExitFullscreen();
            }
        } else {    // 进入全屏
            if (fullarea.requestFullscreen) {
                fullarea.requestFullscreen();
            } else if (fullarea.webkitRequestFullScreen) {
                fullarea.webkitRequestFullScreen();
            } else if (fullarea.mozRequestFullScreen) {
                fullarea.mozRequestFullScreen();
            } else if (fullarea.msRequestFullscreen) {
                // IE11
                fullarea.msRequestFullscreen();
            }
        }
        // fullscreen = !fullscreen;
    })
</script>

 

上一篇:SetCooperativeLevel函数介绍(设置协作等级)


下一篇:JavaScript实现点击一个事件后,触发另一个事件