How to monitor the entry and departure of the page

want to know how the effect in the picture is realized

description: when you open this page, title is changed to "you found it" and reverts to the real title after a few seconds. Modify title, again when you leave this page. What method is used to monitor page switching
page address

Apr.25,2021

determine whether the browser has gained or lost focus, and then dynamically modify title

window.onfocus = function () {
  document.title = "';
};
window.onblur = function () {
  document.title = "';
};

// 
function browser_status(action) {
    // 
    let hidden, state, visibilityChange,status
    if (typeof document.hidden !== "undefined") {
        hidden = "hidden"
        visibilityChange = "visibilitychange"
        state = "visibilityState"
    } else if (typeof document.mozHidden !== "undefined") {
        hidden = "mozHidden"
        visibilityChange = "mozvisibilitychange"
        state = "mozVisibilityState"
    } else if (typeof document.msHidden !== "undefined") {
        hidden = "msHidden"
        visibilityChange = "msvisibilitychange"
        state = "msVisibilityState"
    } else if (typeof document.webkitHidden !== "undefined") {
        hidden = "webkitHidden"
        visibilityChange = "webkitvisibilitychange"
        state = "webkitVisibilityState"
    }

    // title
    document.addEventListener(visibilityChange, function() {
        status = document[state]
        if (document[state] == 'hidden') {
            document.title = "'
        } else {
            document.title = "'
        }
    }, false)
}
Menu