Html5-document.visibilitystate

Source: Internet
Author: User

Document.hidden

This newly-appearing document.hidden property, which shows whether the page is the user's currently viewing page, has 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

Monitoring page Visibility changes is easy:

Various browsers compatible with VAR hidden, state, visibilitychange; if (typeof Document.hidden!== "undefined") {hidden = "hidden"; visibilitychange = "Visibilitychange"; state = "Visibilitys Tate ";} else if (typeof Document.mozhidden!== "undefined") {hidden = "Mozhidden"; visibilitychange = "Mozvisibilitychange"; state = "Mozvisibilitystate";} else if (typeof Document.mshidden!== "undefined") {hidden = "Mshidden"; visibilitychange = "Msvisibilitychange"; state = "M Svisibilitystate ";} else if (typeof Document.webkithidden!== "undefined") {hidden = "Webkithidden"; visibilitychange = " Webkitvisibilitychange "; state =" Webkitvisibilitystate ";} Add listener, show state change in title Document.addeventlistener (Visibilitychange, function () {document.title = Document[state];}, FALSE);//Initialize document.title = Document[state];

The above code will change document.title the value of the page when the visibility changes!

So, when do you need to use visibilitychange events? For example, if you have an embedded video on your page that is playing, when the user switches to another tab, the video on your tab should automatically pause and continue playing when the user switches back. For example, if your page has an automatic refresh action, when the user switches to another tab, you should stop the refresh and continue the previous action when the user switches back.

Hungry is in use, did a title reminder, you can go to see (Toggle tab).

Html5-document.visibilitystate

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.