<font size="3"> 项目中需要将后台浏览器的窗口全屏,也就是我们点击一个按钮要实现按F11全屏的效果。 在HTML5中,W3C制定了关于全屏的API,就可以实现全屏幕的效果,也可以让页面中的图片,视频等全屏目前只有google chrome 15 +, safri5.1+,firfox10+,IE11支持。</font><br> <font size="3"><br> </font><br> <font size="3"><strong>全屏</strong></font><br> <font size="3"><br> </font><br> <div class="blockcode"> <div id="code_RRW"><ol> <li>var docElm = document.documentElement;<br> </li> <li> <br> </li> <li>//W3C <br> </li> <li> <br> </li> <li>if (docElm.requestFullscreen) { <br> </li> <li> <br> </li> <li> docElm.requestFullscreen(); <br> </li> <li> <br> </li> <li>}<br> </li> <li> <br> </li> <li>//FireFox <br> </li> <li> <br> </li> <li>else if (docElm.mozRequestFullScreen) { <br> </li> <li> <br> </li> <li> docElm.mozRequestFullScreen(); <br> </li> <li> <br> </li> <li>}<br> </li> <li> <br> </li> <li>//Chrome等 <br> </li> <li> <br> </li> <li>else if (docElm.webkitRequestFullScreen) { <br> </li> <li> <br> </li> <li> docElm.webkitRequestFullScreen(); <br> </li> <li> <br> </li> <li>}<br> </li> <li> <br> </li> <li>//IE11<br> </li> <li> <br> </li> <li>else if (elem.msRequestFullscreen) {<br> </li> <li> <br> </li> <li> elem.msRequestFullscreen();<br> </li> <li> <br> </li> <li>}</li> </ol></div> <em onclick="copycode($('code_RRW'));">复制代码</em> </div> <font size="3"><br> </font><br> <font size="3"><strong>退出全屏</strong></font><br> <font size="3"><br> </font><br> <div class="blockcode"> <div id="code_93R"><ol> <li>if (document.exitFullscreen) { <br> </li> <li> <br> </li> <li> document.exitFullscreen(); <br> </li> <li> <br> </li> <li>} <br> </li> <li> <br> </li> <li>else if (document.mozCancelFullScreen) { <br> </li> <li> <br> </li> <li> document.mozCancelFullScreen(); <br> </li> <li> <br> </li> <li>} <br> </li> <li> <br> </li> <li>else if (document.webkitCancelFullScreen) { <br> </li> <li> <br> </li> <li> document.webkitCancelFullScreen(); <br> </li> <li> <br> </li> <li>}<br> </li> <li> <br> </li> <li>else if (document.m**itFullscreen) {<br> </li> <li> <br> </li> <li> document.m**itFullscreen();<br> </li> <li> <br> </li> <li>}</li> </ol></div> <em onclick="copycode($('code_93R'));">复制代码</em> </div> <font size="3"><br> </font><br> <font size="3"><strong>事件监听</strong></font><br> <font size="3"><br> </font><br> <div class="blockcode"> <div id="code_AO4"><ol> <li>document.addEventListener("fullscreenchange", function () { <br> </li> <li> <br> </li> <li> fullscreenState.innerHTML = (document.fullscreen)? "" : "not ";}, false); <br> </li> <li> <br> </li> <li> <br> </li> <li> <br> </li> <li>document.addEventListener("mozfullscreenchange", function () { <br> </li> <li> <br> </li> <li> fullscreenState.innerHTML = (document.mozFullScreen)? "" : "not ";}, false); <br> </li> <li> <br> </li> <li> <br> </li> <li> <br> </li> <li>document.addEventListener("webkitfullscreenchange", function () { <br> </li> <li> <br> </li> <li> fullscreenState.innerHTML = (document.webkitIsFullScreen)? "" : "not ";}, false);<br> </li> <li> <br> </li> <li>document.addEventListener("msfullscreenchange", function () {<br> </li> <li> <br> </li> <li> fullscreenState.innerHTML = (document.msFullscreenElement)? "" : "not ";}, false);</li> </ol></div> <em onclick="copycode($('code_AO4'));">复制代码</em> </div> <font size="3"><br> </font><br> <font size="3"><strong>全屏样式设置</strong></font><br> <font size="3"><br> </font><br> <font size="3">在浏览器全屏的使用我们还可以进行样式设置</font><br> <font size="3"><br> </font><br> <div class="blockcode"> <div id="code_2lz"><ol> <li>html:-moz-full-screen { <br> </li> <li> <br> </li> <li> background: red; <br> </li> <li> <br> </li> <li>} <br> </li> <li> <br> </li> <li> <br> </li> <li> <br> </li> <li>html:-webkit-full-screen { <br> </li> <li> <br> </li> <li> background: red; <br> </li> <li> <br> </li> <li>} <br> </li> <li> <br> </li> <li> <br> </li> <li> <br> </li> <li>html:fullscreen { <br> </li> <li> <br> </li> <li> background: red; <br> </li> <li> <br> </li> <li>}</li> </ol></div> <em onclick="copycode($('code_2lz'));">复制代码</em> </div> <font size="3"><br> </font><br> <font size="3"><strong>附录</strong></font><br> <font size="3"><br> </font><br> <font size="3">1 一个在线的Demo</font><br> <font size="3"> <a href="http://robnyman.github.io/fullscreen/" target="_blank">http://robnyman.github.io/fullscreen/</a></font><br> <font size="3">2 HTML5全屏API之网络钓鱼</font><br> <font size="3"> <a href="http://www.36ria.com/5807" target="_blank">http://www.36ria.com/5807</a></font><br> <font size="3">3 jquery封装的全屏插件</font><br> <font size="3"> <a href="http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/" target="_blank">http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/</a></font><br> <font size="3">4 更加详细的全屏API介绍</font><br> <font size="3"> 4.1 <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode" target="_blank">https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode</a></font><br> <font size="3"> 4.2 <a href="https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html" target="_blank">https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html</a></font><br> <br> <br>