HTML5 of page visibility (with code)

Source: Internet
Author: User
Tags visibility
This article brings the content is about the HTML5 page visibility of the Judgment (with code), there is a certain reference value, the need for a friend can refer to, I hope you have some help.

visibilitychangePage events to determine the status of the current page visibility and perform certain tasks specifically

Document.hidden

The newly-emerged document.hidden property that shows whether the page is the user's currently viewing page, with a value of ture or false.

Document.visibilitystate

visibilityStateThe value is either visible (indicates that the page is currently active tab for the browser and the window is not minimized), either (the page is not the Active hidden tab page, or the window is minimized.) ), or prerender (the page is regenerated, not visible to the user.) ).

Visibilitychange Events

Various browsers compatible with VAR hidden, state, visibilitychange; if (typeof Document.hidden!== "undefined") {     hidden = "hidden";    Visibilitychange = "Visibilitychange";     State = "Visibilitystate"; } else if (typeof Document.mozhidden!== "undefined") {     hidden = "Mozhidden";     Visibilitychange = "Mozvisibilitychange";    State = "Mozvisibilitystate"; } else if (typeof Document.mshidden!== "undefined") {     hidden = "Mshidden";     Visibilitychange = "Msvisibilitychange";    State = "Msvisibilitystate"; } else if (typeof Document.webkithidden!== "undefined") {     hidden = "Webkithidden";     Visibilitychange = "Webkitvisibilitychange";    State = "Webkitvisibilitystate"; }//Add listener, Show status change in title Document.addeventlistener (Visibilitychange, function () {     document.title = document[ State]; }, False);//Initialize document.title = Document[state];

Add Listener

Document.addeventlistener ("Visibilitychange", function () {  console.log (document.visibilitystate);}); Document.addeventlistener ("Msvisibilitychange", function () {  console.log (document.msvisibilitystate);}); Document.addeventlistener ("Mozvisibilitychange", function () {  console.log (document.mozvisibilitystate);}); Document.addeventlistener ("Webkitvisibilitychange", function () {  console.log (document.webkitvisibilitystate) ;});

Related articles recommended:

A brief introduction to abstract methods and abstract classes and interfaces in PHP

What are containers (Container) and facades (facade)? Analysis of container and façade in thinkphp5.1

thinkphp template How to determine whether to pay by mobile phone or scan code

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.