Skip to content

Instantly share code, notes, and snippets.

@drenther
Last active August 22, 2018 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drenther/467b7c1c8cd5c8ad6c17efcef4662686 to your computer and use it in GitHub Desktop.
Save drenther/467b7c1c8cd5c8ad6c17efcef4662686 to your computer and use it in GitHub Desktop.
src/pageVisibilityUtils.js for react-page-visibility-example
export const pageVisibilityApi = () => {
let hidden, visibilityChange;
if (typeof document.hidden !== "undefined") {
// Opera 12.10 and Firefox 18 and later support
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
return { hidden, visibilityChange };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment