Question

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");
    }
}
Was it helpful?

Solution

You can use window.location.href

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

instead of

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

OTHER TIPS

Use javascript's setTimeout method:

// redirect to google after 5 seconds
window.setTimeout(function() {
    window.location.href = 'http://www.google.com';
}, 5000);

Why are using window.location.replace? Maybe tha'ts the problem!

**assign(url):** Load the document at the provided URL.
**replace(url):** Replace the current document with the one at the provided URL. The difference from the  assign() method is that after using  replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.

Try using just windows.location.url = ""; And about usin jQuery, just use setTimeOut JS method. Don't mix if not necessary jQuery and Javascript

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top