How can I detect in the browser if the user has the tab (or tab) active ?. Is there any way? Let's say you want to log into the console every time you leave the tab only to know.
How can I detect in the browser if the user has the tab (or tab) active ?. Is there any way? Let's say you want to log into the console every time you leave the tab only to know.
Help me with the link provided by Montoro and here link , which is more useful I have been to add an event listener to "visibilitychange". In this way it would be like this:
document.addEventListener("visibilitychange", function() {
console.log( document.visibilityState );
});
For example if you have a page that plays music when you have the window active and when not, to create a function that plays the music depending on the value of the parameter, this would be an example with the events that trigger in both actions
<body onFocus="Musica_suena(true)" onBlur="Musica_suena(false)">