Answers for "javascript if text box has focus"

5

javascript test if element has focus

var myElement = document.getElementById('myID');
if(myElement === document.activeElement){
    //myElement Has Focus
}
Posted by: Guest on August-01-2019
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 text box has focus"

Code answers related to "Javascript"

Browse Popular Code Answers by Language