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>
标签:控制,fullarea,webkitCancelFullScreen,fullscreen,js,else,全屏,document 来源: https://www.cnblogs.com/h-c-g/p/15080891.html