Chrome quits full Screen issue

Source: Internet
Author: User

Recently made a very flashy B/s display software, display the browser for Google Chrome. Full screen is required, but the page has to exit the full screen button (the LCD screen has no keyboard). Search implementation almost all of the previous article, that is, two JS function one to achieve full screen one exit full screen:
functionRequestfullscreen (Element) {if(Element.requestfullscreen) Element.requestfullscreen (); Else if(Element.msrequestfullscreen) Element.msrequestfullscreen (); Else if(Element.mozrequestfullscreen) Element.mozrequestfullscreen (); Else if(Element.webkitrequestfullscreen) Element.webkitrequestfullscreen ();}functionCancelfullscreen () {if(Document.exitfullscreen) Document.exitfullscreen (); Else if(Document.msexitfullscreen) Document.msexitfullscreen (); Else if(Document.mozcancelfullscreen) Document.mozcancelfullscreen (); Else if(Document.webkitexitfullscreen) Document.webkitexitfullscreen ();}
However, it is found in the actual call that Cancelfullscreen is only valid for the full-screen implementation of the Requestfullscreen and has no effect on the F11 implementation. So think of using requestfullscreen to achieve full-screen, but the problem is requestfullscreen implementation of the full screen only for when the page is valid, when the page jumps when the full-screen effect disappears, so or only through F11 to achieve full screen. and search for one of the exit methods is to add two functions in addition to the above two functions:
 function   IsFullScreen () { return  (document.fullscreenelement && document.fullscreenelement!==  Null  )  | |  Document.mozfullscreen  | |  Document.webkitisfullscreen;}  function   Togglefullscreen (element) { if   (IsFullScreen ()) Cancelfullscreen ();  else   Requestfullscreen (element  | |  document.documentelement);  
Exit full screen by calling the Togglefullscreen function implementation. The implementation principle is: Although previously F11 full screen, but the isfullscreen detection result is still false, so will call Requestfullscreen again full screen. And in the beginning to implement full screen will pop out of the full screen box to implement the Exit function indirectly. However, the method also has a problem that will pop up two times to exit the Full Screen dialog box, one time is the JS Call Full Screen Exit dialog box is F11 Call Full Screen dialog box, as follows: Modify Togglefullscreen as follows will only pop up a dialog box:
function Togglefullscreen (Element) {      | | document.documentelement);      Cancelfullscreen ();}

Full Code reference:

<HTML> <Head>  <MetaCharSet= "Utf-8">  <title></title>  <Scriptsrc=".. /js/jquery-1.10.1.min.js "></Script>  <Script>functionIsFullScreen () {return(Document.fullscreenelement&&document.fullscreenelement!== NULL)         ||Document.mozfullscreen||Document.webkitisfullscreen;}functionRequestfullscreen (Element) {if(Element.requestfullscreen) Element.requestfullscreen (); Else if(Element.msrequestfullscreen) Element.msrequestfullscreen (); Else if(Element.mozrequestfullscreen) Element.mozrequestfullscreen (); Else if(Element.webkitrequestfullscreen) Element.webkitrequestfullscreen ();}functionCancelfullscreen () {if(Document.exitfullscreen) Document.exitfullscreen (); Else if(Document.msexitfullscreen) Document.msexitfullscreen (); Else if(Document.mozcancelfullscreen) Document.mozcancelfullscreen (); Else if(Document.webkitexitfullscreen) Document.webkitexitfullscreen ();}functionTogglefullscreen (Element) {Requestfullscreen (element||document.documentelement);      Cancelfullscreen ();} $ (document). Ready (function(){    $("#exit"). Click (function() {togglefullscreen (document.body);   });   }); </Script> </Head> <Body>  <Divstyle= "padding-top:300px;"></Div>  <ButtonID= "Exit">Exit</Button> </Body></HTML>
View Code

Chrome quits full Screen issue

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.