【问题标题】:Delay on redirect (Javascript)重定向延迟(Javascript)
【发布时间】:2014-06-15 12:07:07
【问题描述】:

我的 JS 不会合作和重定向...谁能看到我的问题?试了一天,好像没什么用:(

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");
    }
}

【问题讨论】:

  • 将window.location.replace更改为window.location.href

标签: javascript login delay settimeout window.location


【解决方案1】:

使用javascript的setTimeout方法:

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

【讨论】:

    【解决方案2】:

    您可以使用window.location.href

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

    而不是

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

    【讨论】:

    • @WhoAreYou:- 不客气!不要忘记接受这个作为答案! :)
    【解决方案3】:

    为什么使用window.location.replace?也许这就是问题所在!

    **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.
    

    尝试只使用windows.location.url = "";而关于使用jQuery,只需使用setTimeOut JS 方法即可。非必要不要混用jQuery和Javascript

    【讨论】:

      猜你喜欢
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 2011-04-10
      相关资源
      最近更新 更多