Shrinivas Pai
Shrinivas Pai

Reputation: 7711

Window redirect to specific location after alert

I have following javascript code which is used to redirect the user to specific location after five seconds.

In Chrome Browser if I run this code keeping the tab active it shows the alert pop up and redirect to the specific location, If tab is not active it will directly go to specific location without alert.

The same is not happening in Firefox if tab is active or not it always show the alert before redirect. Is there a way we can do the same for firefox (similar to what chrome does).

setTimeout(function(){ 
alert("you are redirected"); window.location="https://jsfiddle.net/user/login/" 
}, 5000);

Upvotes: 0

Views: 84

Answers (1)

ibrahim tanyalcin
ibrahim tanyalcin

Reputation: 6501

I'm not sure but maybe document.hidden can be used for this:

setTimeout(function(){ 
    if(!document.hidden){alert("you are redirected");} window.location="https://jsfiddle.net/user/login/" 
    }, 5000);

Upvotes: 1

Related Questions