Active / Offline state of browser tab
Krixnaas
Posted on March 16, 2023
<script>
document.addEventListener("visibilitychange", function() {
document.title = document.hidden ? "I'm away" : "I'm here";
});
document.addEventListener("visibilitychange", (event) => {
if (document.visibilityState == "visible") {
console.log("tab is active")
} else {
console.log("tab is inactive")
}
});
var siteTitle="";
window.addEventListener('blur', () => {
siteTitle = document.title;
document.title = 'Come back! :c';
});
window.addEventListener('focus', () => {
document.title = siteTitle;
});
</script>
π πͺ π
π©
Krixnaas
Posted on March 16, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.