i'm working on a small sale website. i want to use visibilitystate to dictate when the user navigates to a new page, switches tabs, closes the tab, minimizes or closes the browser, or, on mobile, switches from the browser to a different app. to return a new URL. document.addEventListener("visibilitychange", () => {
if (document.visibilityState === 'hidden') {
setTimeout(function(){
window.location.href = 'www.google.com';
}, 1000);