Skip to content

Instantly share code, notes, and snippets.

@arguiot
Created March 17, 2018 13:15
Show Gist options
  • Save arguiot/8fc39dc990270ad4d28352bbf65c7922 to your computer and use it in GitHub Desktop.
Save arguiot/8fc39dc990270ad4d28352bbf65c7922 to your computer and use it in GitHub Desktop.
On focus event in JS
const event = new Event("focused");
let focused = true;
setInterval(() => {
if (document.hasFocus() && !focused) {
document.dispatchEvent(event);
focused = true;
} else if (focused) {
document.dispatchEvent(event);
focused = false;
}
}, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment