Page Monitor status change site title

Source: Internet
Author: User

We have long lacked a way to judge whether a user is browsing a specified tab. Does the user go to another website? Did they switch back?

Now, the HTML5 page visibility interface gives programmers a way to use Visibilitychange page events to determine the state of the current page visibility and to perform certain tasks in a targeted manner. There are also new Document.hidden properties that can be used.

Document.hidden

This new Document.hidden property, which shows whether the page is the page that the user is currently viewing, with a value of ture or false.

Document.visibilitystate

The value of visibilitystate is either visible (indicates that the page is currently active tab for the browser, and the window is not minimized), or hidden (the page is not the active 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:

<script>varThistitle = Document.<a href="Http://doocii.com/tag/title"title="title">title</a>; function Handlevisibilitychange () {if(Document.hidden) {document.<a href="Http://doocii.com/tag/title"title="title">title</a> ="? (-) | "+Thistitle; } Else{document.title=Thistitle; } } //Monitor page StatusDocument.addeventlistener ("Visibilitychange", Handlevisibilitychange,false); </script>

Page Monitor status change site title

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.