Using HTML5 JS to implement full screen browser

Source: Internet
Author: User

The project needs to be the Background browser window full screen, that is, we click on a button to achieve the effect of pressing F11 full screen. In the HTML5, the website has developed a full-screen API, you can achieve the full display effect, you can also make the page images, videos and other full screen currently only Google Chrome +, SAFRI5.1+,FIRFOX10+,IE11 support

Fullscreen?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 var docElm = document.documentElement; //W3 if (docElm.requestFullscreen) {      docElm.requestFullscreen();  } //FireFox  else if (docElm.mozRequestFullScreen) {      docElm.mozRequestFullScreen();  } //Chrome等  else if (docElm.webkitRequestFullScreen) {      docElm.webkitRequestFullScreen();  } //IE11 else if (elem.msRequestFullscreen) {   elem.msRequestFullscreen(); }
Exit Full Screen?
1 2 3 4 5 6 7 8 9 10 11 12 if (document.exitFullscreen) {      document.exitFullscreen();  else if (document.mozCancelFullScreen) {      document.mozCancelFullScreen();  else if (document.webkitCancelFullScreen) {      document.webkitCancelFullScreen();  } else if (document.msExitFullscreen) {       document.msExitFullscreen();}
Event Monitoring?
1 2 3 4 5 6 7 8 9 10 document.addEventListener("fullscreenchange", function () {      fullscreenState.innerHTML = (document.fullscreen)? "" : "not ";}, false);    document.addEventListener("mozfullscreenchange", function () {      fullscreenState.innerHTML = (document.mozFullScreen)? "" : "not ";}, false);    document.addEventListener("webkitfullscreenchange", function () {      fullscreenState.innerHTML = (document.webkitIsFullScreen)? "" : "not ";}, false); document.addEventListener("msfullscreenchange", function () {     fullscreenState.innerHTML = (document.msFullscreenElement)? "" : "not ";}, false);
Full-screen style settings

In the browser full-screen use We can also make style settings

?
1 2 3 4 5 6 7 8 9 10 11 html:-moz-full-screen     background: red   html:-webkit-full-screen     background: red    html:fullscreen {      background: red }
Appendix

11 Online Demos

http://robnyman.github.io/fullscreen/

2 HTML5 full Screen API phishing

http://www.36ria.com/5807

3 Full-screen plugin for jquery packages

http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/

4 more detailed full-screen API introduction

4.1 Https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode

    4.2  https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.