js全屏解决方案

    xiaoxiao2022-07-04  138

    <script type="text/javascript"> document.onkeydown=function(e){ e = e|| window.event || arguments.callee.caller.arguments[0]; if(e && e.keyCode==122){ //fullScreen(); document.getElementById('bt').onclick(); e.preventDefault(); e.stopPropagation(); } } function FullScreen(el) { var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen; if (!isFullscreen) {//进入全屏,多重短路表达式 (el.requestFullscreen && el.requestFullscreen()) || (el.mozRequestFullScreen && el.mozRequestFullScreen()) || (el.webkitRequestFullscreen && el.webkitRequestFullscreen()) || (el.msRequestFullscreen && el.msRequestFullscreen()); } else { //退出全屏,三目运算符 document.exitFullscreen ? document.exitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.webkitExitFullscreen ? document.webkitExitFullscreen() : ''; } } function toggleFullScreen(e) { var el = e.srcElement || e.target;//target兼容Firefox el.innerHTML == '点我全屏' ? el.innerHTML = '退出全屏' : el.innerHTML = '点我全屏'; FullScreen(el); } </script> <button id="bt" onclick="toggleFullScreen(event)">点我全屏</button>
    最新回复(0)