1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <title>js进入全屏</title> </head>
<body> <button id='btn'>进入全屏</button> <div id="content" style="background:yellow;width:500px;height:500px;"> <div>测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容</div> <a href="#" id="quite" class="btn">退出全屏</a> </div>
<script> function fullScreen(el) { var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen, wscript if (typeof rfs != "undefined" && rfs) { rfs.call(el); return; } if (typeof window.ActiveXObject != "undefined") { wscript = new ActiveXObject("WScript.Shell"); if (wscript) { wscript.SendKeys("{F11}"); } } } function exitFullScreen(el) { var el = document, cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen, wscript; if (typeof cfs != "undefined" && cfs) { cfs.call(el); return; } if (typeof window.ActiveXObject != "undefined") { wscript = new ActiveXObject("WScript.Shell"); if (wscript != null) { wscript.SendKeys("{F11}"); } } } var btn = document.getElementById('btn'); var content = document.getElementById('content'); btn.onclick = function () { fullScreen(content); } var quite = document.getElementById('quite'); quite.onclick = function () { exitFullScreen(); } </script> </body>
</html>
|