Detecting page activity status via HTML5 Visibility API

Source: Internet
Author: User

A few years ago, when we browsed the Web page, there was no tabbed browsing mode, each page would be a browser window, and if I remember correctly, we all browsed the Web before Win7. As a programmer, we often open 10-15 pages in conjunction with each other, and more than 20 are not surprising.

Why use this API?

Early on we had no way to determine which tabs were active, but now through the HTML Visibility API we can detect if a visitor is browsing our interface.

In this tutorial we'll show you how to use the HTML5 Visibility API, and we've prepared a simple demo to check the status of the page. In the demo, we will modify the title of the document according to the status of the page.

View the status of a page

With the advent of this API, we have ushered in two new document attributes, namely Document.visibilitystate and Document.hidden.

The document.visibilitystate has four selectable values:

    • Hidden: The page has not been browsed on any screen.

    • PreRender: The page is in the tab, but the visitor is not on this tab now.

    • visible: visitors are browsing.

    • unloaded: The page has been loaded and now jumps to the other interface.

Document.hidden is a Boolean-type property.

Now we can control our website according to the state of the page.

Now we can immediately know the availability property of our page. But the first thing we have to do is listen to this event, so that we can do something accordingly. I have written a simple listener event:

......

......

Read the original: Detect page activity status via HTML5 Visibility API

Detecting page activity status via HTML5 Visibility API

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.