Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay on redirect (Javascript)

My JS wont cooperate and redirect... Can anyone see my problem? Tried all day, it's like nothing works :(

function validate(form) {
    if (form.username.value==="admin") { 
        if (form.password.value==="1") {
            $('#loginLock').css({opacity: 0});
            $('#loginUnlock').css({opacity: 1});
            document.cookie="username=Admin";
            setTimeout(function(){ window.location.replace = 'vault.php';}, 1500);
        } else {
            alert("Forkert brugernavn eller password");
        }
    } else {
        alert("Forkert brugernavn eller password");
    }
}
like image 848
WhoAreYou Avatar asked Sep 12 '25 09:09

WhoAreYou


2 Answers

You can use window.location.href

 setTimeout(function(){ window.location.href= 'vault.php';}, 1500);

instead of

setTimeout(function(){ window.location.replace = 'vault.php';}, 1500);
like image 135
Rahul Tripathi Avatar answered Sep 13 '25 22:09

Rahul Tripathi


Use javascript's setTimeout method:

// redirect to google after 5 seconds
window.setTimeout(function() {
    window.location.href = 'http://www.google.com';
}, 5000);
like image 27
Rubyist Avatar answered Sep 14 '25 00:09

Rubyist