Pregunta

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");
    }
}
¿Fue útil?

Solución

You can use window.location.href

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

instead of

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

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top