Click a button in html5 js to achieve full screen browser Effect

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 pages. Currently, only google chrome 15 +, safri5.1 +, supported by firfox10 + and IE11

Full Screen
Copy codeThe Code is as follows:
Var docElm = document.doc umentElement;
// W3C
If (docElm. requestFullscreen ){
DocElm. requestFullscreen ();
}
// FireFox
Else if (docElm. Fetch requestfullscreen ){
DocElm. requestfullscreen ();
}
// Chrome, etc.
Else if (docElm. webkitRequestFullScreen ){
DocElm. webkitRequestFullScreen ();
}
// IE11
Else if (elem. msRequestFullscreen ){
Elem. msRequestFullscreen ();
}

Exit full screen
Copy codeThe Code is as follows:
If (document. exitFullscreen ){
Document. exitFullscreen ();
}
Else if (document. canccancelfullscreen ){
Document. Define cancelfullscreen ();
}
Else if (document. webkitCancelFullScreen ){
Document. webkitCancelFullScreen ();
}
Else if (document. msExitFullscreen ){
Document. msExitFullscreen ();
}

Event listening
Copy codeThe Code is as follows:
Document. addEventListener ("fullscreenchange", function (){
FullscreenState. innerHTML = (document. fullscreen )? "": "Not" ;}, false );

Document. addEventListener ("mozfullscreenchange", function (){
FullscreenState. innerHTML = (document. Specify fullscreen )? "": "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

You can also set the style when using full screen in the browser.
Copy codeThe Code is as follows:
Html:-moz-full-screen {
Background: red;
}

Html:-webkit-full-screen {
Background: red;
}

Html: fullscreen {
Background: red;
}

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.