Example of JavaScript full screen and exit full screen code

Source: Internet
Author: User

Js enables full screen and exit of browser windows. Mainstream browsers on the market, such as Google, Firefox, and 360, are compatible, however, the earlier version of IE is a bit defective (the status bar at the bottom still exists in full screen mode ).

This demo is basically enough. Copy the following source code and save it as an html file to see the effect.

<! DOCTYPE html>
<Html>
<Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"/>
<Title> JavaScript full screen and exit full screen code </title>
<Body>
<! -- RequestFullScreen(document.doc umentElement): The entire webpage enters full screen.
RequestFullScreen (document. getElementById ("video-box"): specifies the full screen of a certain area.
-->
<Button onclick = "requestFullScreen(document.doc umentElement)"> full screen display </button>
<Button onclick = "exitFull ()"> exit full screen </button>
</Body>
<Script type = "text/javascript">
Function requestFullScreen (element ){
// Judge various browsers and find the correct method
Var requestMethod = element. requestFullScreen | // W3C
Element. webkitRequestFullScreen | // Chrome, etc.
Element. Inclurequestfullscreen | // FireFox
Element. msRequestFullScreen; // IE11
If (requestMethod ){
RequestMethod. call (element );
    }
Else if (typeof window. ActiveXObject! = "Undefined") {// for Internet Explorer
Var wscript = new ActiveXObject ("WScript. Shell ");
If (wscript! = Null ){
Wscript. SendKeys ("{F11 }");
        }
    }
}
// Exit full screen to determine the browser type
Function exitFull (){
// Judge various browsers and find the correct method
Var exitMethod = document. exitFullscreen | // W3C
Document. Optional cancelfullscreen | // Chrome, etc.
Document. webkitExitFullscreen | // FireFox
Document. webkitExitFullscreen; // IE11
If (exitMethod ){
ExitMethod. call (document );
    }
Else if (typeof window. ActiveXObject! = "Undefined") {// for Internet Explorer
Var wscript = new ActiveXObject ("WScript. Shell ");
If (wscript! = Null ){
Wscript. SendKeys ("{F11 }");
        }
    }
}
</Script>
</Html>

Related Article

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.