Detecting Tab Switching in Browser

Greetings,

Switch from one tab to another in browsers Page Visibility API through we can understand. “visibilityState” status of the tab is kept in the property.

As an example, you can review the code below:

document.addEventListener("visibilitychange", function() {
console.log(document.visibilityState);
});

As you can see tab changes “visibilitychange” catching the event. “visibilityState” feature takes the following values:

visible: The browser tab is active and the browser window is not minimized.

hidden: The browser tab is inactive, the tab has been changed, or the browser window has been minimized.

--

--