Created
March 17, 2018 13:15
-
-
Save arguiot/8fc39dc990270ad4d28352bbf65c7922 to your computer and use it in GitHub Desktop.
On focus event in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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