JavaScript full screen displays page elements in Full-screen mode _javascript tips

Source: Internet
Author: User

The easiest way to do this is to dynamically change the style of the part you want to display in full screen, such as position into absolute,height and width, and then change the background color to white (to cover the rest of the page). This page can only see you want to highlight the parts, visually equivalent to full screen. While using JavaScript to monitor keyboard events, once the user presses ESC to exit the key, it restores the original appearance. Some of the code is as follows:

Copy Code code as follows:

Document.onkeydown = function (event) {
var e = Event | | window.event | | Arguments.callee.caller.arguments[0];
if (e && e.keycode = =) {//esc key

$ ('. Navbar-inner '). FadeIn (100);
var maintable = document.getElementById ("Holder");
Maintable.style.position = "relative";
Maintable.style.height = "100%";
Maintable.style.width = "100%";
maintable = document.getElementById ("main");
Maintable.style.height = "100%";
Maintable.style.width = "100%";
Maintable.style.left = 0 + "px";
Maintable.style.top = 0 + "px";
Resizeplots ();
}
};


Fullscreenclick:function () {

$ ('. Navbar-inner '). fadeout (100);

var maintable = document.getElementById ("Holder");
Maintable.style.position = "absolute";
Maintable.style.background = "#fff";
Maintable.style.zIndex = 5;
Maintable.style.height = $ (window). Height () + "px";
Maintable.style.width = $ (window). Width () + "px";
Maintable.style.left = 0 + "px";
Maintable.style.top = 0 + "px";
maintable = document.getElementById ("main");
Maintable.style.height = "90%";
Maintable.style.width = "90%";
Maintable.style.left = $ (window). Width () * 0.05 + "px";
Maintable.style.top = $ (window). Height () * 0.02 + "px";
Resizeplots ();
},


But there is a drawback, that is, you still need to manually click F11 to achieve a real full screen.

Here's a way to not press F11 yourself:

Copy Code code as follows:

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<body >

<button id= "BTN" > Full screen </button>

<div id= "Content" style= "Height:500px;width:500px;background: #fff" >
<p> believe in music, believe May day </p>
</div>

</body>

<script language= "JavaScript" >
document.getElementById ("Btn"). Onclick=function () {
var elem = document.getElementById ("content");
Requestfullscreen (Elem);
};

function Requestfullscreen (Element) {

var Requestmethod = Element.requestfullscreen | | Element.webkitrequestfullscreen | | Element.mozrequestfullscreen | | Element.msrequestfullscreen;

if (Requestmethod) {
Requestmethod.call (Element);
else if (typeof window. ActiveXObject!== "undefined") {
var wscript = new ActiveXObject ("Wscript.Shell");
if (wscript!== null) {
WScript. SendKeys ("{F11}");
}
}
}

</script>


This can support most browsers. But the annoying IE still cannot support HTML5 Full-screen function, need to simulate press F11 this action. The reader can see it in the code.

You can also exit the full screen interface in your code:

Copy Code code as follows:

function Cancelfullscreen (EL) {
var Requestmethod = el.cancelfullscreen| | el.webkitcancelfullscreen| | el.mozcancelfullscreen| | El.exitfullscreen;
if (Requestmethod) {//Cancel full screen.
Requestmethod.call (EL);
else if (typeof window. ActiveXObject!== "undefined") {//older IE.
var wscript = new ActiveXObject ("Wscript.Shell");
if (wscript!== null) {
WScript. SendKeys ("{F11}");
}
}
}

About Full-screen display, I am still very curious, then video site is how to do for IE and other browsers are compatible with Full-screen function. If anyone knows, please share, thank you.

Updated (2013/09/22)

Most of the time, you want to do some customization when you switch Full-screen. You can bind an event as follows:

Copy Code code as follows:

Document.addeventlistener ("Fullscreenchange", function () {
Doit ();
}, False);

Document.addeventlistener ("Mozfullscreenchange", function () {
Doit ();
}, False);

Document.addeventlistener ("Webkitfullscreenchange", function () {
Doit ();
}, False);

It triggers the doit () operation every time you enter or exit the full screen.

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.