广告
将以下代码插入到index.html内<body>下。附件上传到/js下刷新。
<center> <input type="button" onClick="fullscreen()" value="安卓全屏常亮" /> <script src="js/nosleep.min.js"></script> <script> //init noSleep var noSleep = new NoSleep(); // Enable wake lock. // (must be wrapped in a user input event handler e.g. a mouse or touch handler) // noSleep.enable()初始化方法必须绑定在鼠标事件或触摸事件内, // 当点击页面时就会激活不休眠功能 document.addEventListener('click', function enableNoSleep() { document.removeEventListener('click', enableNoSleep, false); noSleep.enable(); console.log('enable noSleep'); }, false); </script> <script> // 全屏 function fullscreen() { var docElm = document.documentElement; if (docElm.requestFullscreen) { docElm.requestFullscreen(); } else if (docElm.mozRequestFullScreen) { docElm.mozRequestFullScreen(); } else if (docElm.webkitRequestFullScreen) { docElm.webkitRequestFullScreen(); } else if (docElm.msRequestFullscreen) { docElm.msRequestFullscreen(); } } // 退出全屏 function exitFullscreen() { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitCancelFullScreen) { document.webkitCancelFullScreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } } // 监听是否全屏 window.onload = function() { var elem = document.getElementById('state'); document.addEventListener('fullscreenchange', function() { elem.innerText = document.fullscreen ? 'yes': 'no'; }, false); document.addEventListener('mozfullscreenchange', function() { elem.innerText = document.mozFullScreen ? 'yes': 'no'; }, false); document.addEventListener('webkitfullscreenchange', function() { elem.innerText = document.webkitIsFullScreen ? 'yes': 'no'; }, false); document.addEventListener('msfullscreenchange', function() { elem.innerText = document.msFullscreenElement ? 'yes': 'no'; }, false); } </script> </center>