Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

private-face/mozvisibility

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MozVisibility

Page Visibility API allows site developers to programmatically determine the current visibility of a document and be notified of visibility changes. At this moment Page Visibility API is natively supported in Chrome 13+, Firefox 10+ and IE10. MozVisibility is designed to partially emulate Page Visibility API in older Firefox versions (5—9).

How it works

Functioning principle of this library is based on the following feature, introduced in Firefox 5.0: when the page is in inactive tab Firefox clamps setTimeout/setInterval that lesser than 1 second to 1 second.

Therefore, by setting timeout with 500ms delay and calculating the actual delay between setting and firing timeout, we can determine whether page visible or not.

Usage

Add mozvisibility.js to your project.

document.mozVisibilityState & document.mozHidden

You can use the following properties to determine whether page visible or not:

document.mozVisibilityState 	// can be ‘visible’ or ‘hidden’
document.mozHidden // can be true or false

“mozvisibilitychange” event

document.addEventListener("mozvisibilitychange", function () {
	console.log(‘Page became', document.mozHidden ? 'invisible' : 'visible');
}, false);

Visibility.js

You can also use this library in conjunction with Visibility.js. In this case include mozvisibility.js BEFORE visibility.js.

Limitations & known issues

  • Only ‘visible’ and ‘hidden’ states are supported.
  • The library determines page as ‘hidden’ ONLY when it is in the background tab. Other types of invisibility cannot be detected at this time.
  • There is a 1 second delay between the moment when page became invisible and firing “mozvisibilitychange” event.
  • Doesn’t work in IFRAME.

Read more

License

MIT License

Copyright © 2011 Vladimir Zhuravlev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Page Visibility API emulation for Firefox 5+

Resources

License

Stars

Watchers

Forks

Packages

No packages published