Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: filereader check file type 
Javascript :: jquery fade out 
Javascript :: react pagination 
Javascript :: distance to km javascript 
Javascript :: keep-alive vuejs router 
Javascript :: regex optional whitespace characters 
Javascript :: cypress check attribute for each element 
Javascript :: chrome extension open new tab from popup 
Javascript :: mongoose reset database 
Javascript :: how to run js before submit html 
Javascript :: jquery on wheel event 
Javascript :: Terminating timed out worker 
Javascript :: object fromentries example 
Javascript :: remove duplicated from array of ojects 
Javascript :: how to show 1 to 10 odd numbers in javascript 
Javascript :: show hidden element javascript 
Javascript :: ngstyle background url angular 
Javascript :: nested object javascript 
Javascript :: payloadtoolargeerror node js 
Javascript :: javascript password hashing 
Javascript :: react native paper text input 
Javascript :: javascript log to console 
Javascript :: saving text in javascript 
Javascript :: how to run commands in the command prompt using javascript 
Javascript :: create csv file javascript 
Javascript :: node print variable 
Javascript :: initialize express app 
Javascript :: set timeout for loop 
Javascript :: javascript get item in array by id 
Javascript :: new date parameters javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =