Posted in Javascript onJuly 05, 2018
本文实例讲述了JavaScript控制浏览器全屏显示。分享给大家供大家参考,具体如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>3water.com JS全屏显示</title> </head> <body> <div onclick="launchFullscreen(document.documentElement);">全屏显示</div> <div onclick="exitFullscreen()(document.documentElement);">退出全屏</div> <!--launchFullscreen(document.documentElement);--> </body> </html> <script> // 判断各种浏览器,找到正确的方法 function launchFullscreen(element) { if(element.requestFullscreen) { element.requestFullscreen(); } else if(element.mozRequestFullScreen) { element.mozRequestFullScreen(); } else if(element.webkitRequestFullscreen) { element.webkitRequestFullscreen(); } else if(element.msRequestFullscreen) { element.msRequestFullscreen(); } } // 判断浏览器种类 function exitFullscreen() { if(document.exitFullscreen) { document.exitFullscreen(); } else if(document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if(document.webkitExitFullscreen) { document.webkitExitFullscreen(); } } // 退出全屏模式! exitFullscreen(); </script>
使用本站HTML/CSS/JS在线运行测试工具:http://tools.3water.com/code/HtmlJsRun,可得到如下测试运行效果:
希望本文所述对大家JavaScript程序设计有所帮助。
JavaScript控制浏览器全屏显示简单示例
- Author -
angularWQ声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@