Answers for "javascript if browser out of focus"

1

javascript if browser out of focus

var 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";
}
function handleVisibilityChange() {
  if (document[hidden]) {
  	// Do here something if page is hidden (not in focus)
  } else {
    // Do here something if page is in focus
  }
}
if (typeof document.addEventListener === "undefined" || hidden === undefined) { // Skip if the browser doesn't support addEventListener or the Page Visibility API
} else {
  document.addEventListener(visibilityChange, handleVisibilityChange, false); // Handle page visibility change
}
Posted by: Guest on April-14-2021

Code answers related to "javascript if browser out of focus"

Code answers related to "Javascript"

Browse Popular Code Answers by Language