簡體   English   中英

如果條件為真,將用戶重定向到另一個html頁面

[英]redirect user to another html page if the condition is true

首先,我只想說我對html不好,我對html的了解僅來自我自己在網上學到的東西。

所以..我有一個項目,其中一部分正在建立一個網站。 我已經做了網站,但是我有一個問題。

我的問題是我不想讓用戶訪問該設置,我希望管理員僅訪問該設置,我通過在設置頁面中輸入密碼來做到這一點。因此,如果用戶單擊設置圖標,它將要求輸入密碼,如果密碼正確,則用戶可以轉到設置頁面

我在index.html中有3個頁面(index.html是我的主頁),(manager.html是我的設置代碼所在的地方)和(index4是該代碼所在的地方),那里有一個代碼可以讓用戶轉到index4。 html頁面和index4.html頁面中的代碼是

<!DOCTYPE html>

<html>

<body>

    <script>
        var pass;
        pass = prompt("please enter the password to access");
        if (pass == "11111"){
            <a href="manager.html">This is the link.</a>        
        } else {
            document.write("The password you've is enter is incorrect");
        }
</script>

<body>  

</html>

根據我在網上學到的知識,href =“ link”代碼可以重定向到另一頁。.但是,如果它位於'if statement'中,則似乎無法使用它。 當我檢查元素時,出現此錯誤“意外令牌'<'”

有人可以告訴我如何糾正我的錯誤。

另一種方法是用作波紋管。 檢查此鏈接

例如:

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";

嘗試設置document.location.href更多關於這里

 var pass; pass = prompt("please enter the password to access"); if (pass == "11111") { document.location.href = "manager.html"; } else { document.write("The password you've is enter is incorrect"); } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM