In the browser inactive tab, javascript alert is sometimes ignored and the page is moved

182 views Asked by At

I implemented the logout function in JS if 5 minutes have passed by checking every 1 second as shown below.

// logout
let restAutologoutTime = (60 * 5); // 5minute
autoLogout = setInterval(function() {
    --restAutologoutTime;
    if(restAutologoutTime <= 0) {
        // clear 
        clearInterval(autoLogout);
        setTimeout(function() {
            alert('logout');
            location.href = 'somethingUrl';
        }, 1000)
    }
}, 1000);

If the tab is active, an alert is executed and the location only occurs when 'OK' is pressed. (chrome, edge browser) However, if the tab was not active (turn on another tab and search), sometimes the location was executed without alert. It knows that browsers reduce resources on inactive tabs.

Is there a way to make the location move after the alert window is exposed, regardless of tab activation or deactivation?

0

There are 0 answers