Skip to content
A cross-browser plugin for using the Page Visibility API
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test Update getHiddenProp test
.gitignore Add tests
.jshintrc Add tests
.travis.yml Use Firefox for Travis tests
LICENSE.md
README.md Use Firefox for Travis tests
bower.json Update UMD loader for Browserify
karma.conf.js
package.json
visibility.js

README.md

visibility.js

A cross-browser plugin for using the Page Visibility API

Build Status

Installation

  • Download: zip
  • Bower: bower install visibility.js
  • Git: git clone https://github.com/alexgibson/visibility.js

Setup

This component can be used as an AMD module, CommonJS module, or a global.

To use create a new Visibility instance, passing the relevant callbacks you need.

var page = new Visibility({
    onHidden: hiddenCallback,
    onVisible: visibleCallback
});

function hiddenCallback () {
    console.log('hidden callback');
}

function visibleCallback () {
    console.log('visible callback');
}

Useful methods

  • isHidden (returns boolean) - manually check to see if the page is hidden
  • isSupported (returns boolean) - test for Page Visibility API browser support
  • destroy - remove visibilitychange event listener and unregister callbacks

Supported web browsers

See http://caniuse.com/#feat=pagevisibility

Something went wrong with that request. Please try again.