I want to change the title of the page when visitor at another tab. I checked the forum but I need something like this;
(function titleScroller(text) {
document.title = text;
console.log(text);
setTimeout(function () {
titleScroller(text.substr(1) + text.substr(0, 1));
}, 200);
}("Come back please ❤" + " " +"Miss you ❤" + " " + "Hello? ❤" + " " ));
or can I add scrolling title to this code?
jQuery(document).ready(function($) {
// any code js
var title = document.title;
var alttitle = "Miss You ❤";
window.onblur = function () { document.title = alttitle; };
window.onfocus = function () { document.title = title; };
});
You can listen for visibilitychange event in your code and trigger whatever function you like.
document.addEventListener("visibilitychange", event => {
if (document.visibilityState == "visible") {
console.log("tab is active")
} else {
console.log("tab is inactive")
}
})