visibility-change-ponyfill

A more reliable visibilitychange event that works in more mobile WebViews


Keywords
browser, visibility, change, visibilitychange, ios, mobile, chrome, event, pageshow, pagehide, android, uiwebview, webview, ponyfill, app
License
MIT
Install
npm install visibility-change-ponyfill@2.0.1

Documentation

visibility-change-ponyfill

A more reliable visibilitychange event that works in more mobile WebViews

gzipped size Travis build status npm version

Install

npm install --save visibility-change-ponyfill
import onVisibilityChange from 'visibility-change-ponyfill';

If you don't use node/babel, include this:

<script src="dist/visibility-change-ponyfill.browser.js"></script>

Usage

To add a listener:

onVisibilityChange(function () {
	if(document.hidden) {
		// this page is now hidden
	} else {
		// this page is now visible
	}
});

To remove a listener:

function yourOnChangeListener() { /* */ };
onVisibilityChange(yourOnChangeListener);

onVisibilityChange.remove(yourOnChangeListener);

To remove all listeners:

onVisibilityChange.removeAll();

License

MIT © Federico Brigante