JS make the page full screen

Source: Internet
Author: User

Overview

Accidental Discovery A page has a button to make the Web page full screen, check the next code discovery is H5 full-screen API, so looked up the next information, recorded for later development of reference, I believe for other people also useful.

Resources:
Using JS how to make the page full screen and not full screen function
Element.requestfullscreen () MDN

Full Screen API

H5 has a full-screen API, theElement.requestfullscreen () method is used to emit an asynchronous request to bring the element into full-screen mode.

It is important to note that only standard HTML elements, elements, and elements that are contained within the top-level document <svg> <math> , as well as the inner elements of an IFRAME with the allowFullScreen attribute, can enter full-screen mode. This means that elements inside the frame, as well as the inner elements of object, cannot enter full-screen mode.

The sample code is as follows:

<!doctype html>
Full-screen Event

If the element is allowed to enter full-screen mode, the document object receives a Fullscreenchange event informing the caller that the current element has entered full-screen mode. If the full-screen request is not licensed, you will receive a Fullscreenerror event .

Examples are as follows:

document.addEventListener('fullscreenchange', function(){ /*code*/ });document.addEventListener('webkitfullscreenchange', function(){ /*code*/});document.addEventListener('mozfullscreenchange', function(){ /*code*/});document.addEventListener('MSFullscreenChange', function(){ /*code*/});document.addEventListener('fullscreenerror', function(){ /*code*/ });document.addEventListener('webkitfullscreenerror', function(){ /*code*/});document.addEventListener('mozfullscreenerror', function(){ /*code*/);document.addEventListener('MSFullscreenError', function(){ /*code*/ });
Full Screen style

After full screen, you can also choose to adjust the style , just like hover, as follows:

:-webkit-full-screen { }:-moz-full-screen { }:-ms-fullscreen { }:fullscreen { }

JS make the page full screen

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.