Full Screen browser with html5js-

Source: Internet
Author: User
In the project, you need to screen the background browser window, that is, click a button to achieve full screen press F11. In HTML5, W3C has developed an API for full screen to achieve full screen effects. It can also enable full screen effects such as images and videos on the page. Currently, only googlechrome15 +, sa..., can be used ...,. In the project, you need to screen the background browser window, that is, click a button to achieve full screen press F11. In HTML5, W3C has developed an API for full screen to achieve full screen effects. It can also enable full screen effects such as images and videos on pages. Currently, only google chrome 15 +, safri5.1 +, supported by firfox10 + and IE11.


Full Screen


  1. Var docElm = document.doc umentElement;

  2. // W3C

  3. If (docElm. requestFullscreen ){

  4. DocElm. requestFullscreen ();

  5. }

  6. // FireFox

  7. Else if (docElm. Fetch requestfullscreen ){

  8. DocElm. requestfullscreen ();

  9. }

  10. // Chrome, etc.

  11. Else if (docElm. webkitRequestFullScreen ){

  12. DocElm. webkitRequestFullScreen ();

  13. }

  14. // IE11

  15. Else if (elem. msRequestFullscreen ){

  16. Elem. msRequestFullscreen ();

  17. }



Exit full screen


  1. If (document. exitFullscreen ){

  2. Document. exitFullscreen ();

  3. }

  4. Else if (document. canccancelfullscreen ){

  5. Document. Define cancelfullscreen ();

  6. }

  7. Else if (document. webkitCancelFullScreen ){

  8. Document. webkitCancelFullScreen ();

  9. }

  10. Else if (document. m ** itFullscreen ){

  11. Document. m ** itFullscreen ();

  12. }



Event listening


  1. Document. addEventListener ("fullscreenchange", function (){

  2. FullscreenState. innerHTML = (document. fullscreen )? "": "Not" ;}, false );



  3. Document. addEventListener ("mozfullscreenchange", function (){

  4. FullscreenState. innerHTML = (document. Specify fullscreen )? "": "Not" ;}, false );



  5. Document. addEventListener ("webkitfullscreenchange", function (){

  6. FullscreenState. innerHTML = (document. webkitIsFullScreen )? "": "Not" ;}, false );

  7. Document. addEventListener ("msfullscreenchange", function (){

  8. FullscreenState. innerHTML = (document. msFullscreenElement )? "": "Not" ;}, false );



Full Screen style settings


You can also set the style when using full screen in the browser.


  1. Html:-moz-full-screen {

  2. Background: red;

  3. }



  4. Html:-webkit-full-screen {

  5. Background: red;

  6. }



  7. Html: fullscreen {

  8. Background: red;

  9. }



Appendix


1. An Online Demo
Http://robnyman.github.io/fullscreen/
2 HTML5 full-screen API phishing
Http://www.36ria.com/5807
3. jquery-encapsulated full-screen plug-in
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.