Is there a way that when I click on my browser, and give it focus, to run a method once? And then when the browser loses focus and then gets the focus back to again run that method only once, again.
Is there a way that when I click on my browser, and give it focus, to run a method once? And then when the browser loses focus and then gets the focus back to again run that method only once, again.
function blinkTab() {
const browserTitle = document.title;
const stopBlinking = () => {
document.title = browserTitle;
};
const startBlinking = () => {
document.title = 'My New Title';
};
function registerEvents() {
window.addEventListener("focus", function(event) {
stopBlinking();
}, false);
window.addEventListener("blur", function(event) {
setInterval(() => {
startBlinking();
}, 500);
}, false);
};
registerEvents();
};
blinkTab();