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