简体   繁体   English

如何根据输入的密码重定向到特定的 URL?

[英]How to redirect to specific URL depending on password entered?

I have a password-protected button that will redirect a user to a specific URL when the password is entered.我有一个受密码保护的按钮,当输入密码时,该按钮会将用户重定向到特定的 URL。 It works fine but what I want to do is depending on what password the user enters, they will be taken to a URL which corresponds to what they entered.它工作正常,但我想做的是取决于用户输入的密码,他们将被带到与他们输入的密码相对应的 URL。 Let's say 'test' was entered in the box, this will redirect users to 'test.com/test/test.html' but if the user entered 'test1' then they'll be redirected to 'test.com/test1/test1.html'.假设在框中输入了“test”,这会将用户重定向到“test.com/test/test.html”,但是如果用户输入了“test1”,那么他们将被重定向到“test.com/test1/test1” .html'。 Is there any way to do this?有没有办法做到这一点? This is my code:这是我的代码:

 <body> <div id="title"> <span>WELCOME TO</span> <span style="font-size:80px"><br> AiZen</span> </div> <div class="button_container"> <button class="btn" id="HyperLink1" onclick="location.href='home.html';return ValidatePassword()"><span>Enter Now</span></button> </div> <script> function ValidatePassword() { var a = prompt("Enter the password. You know it right?", ""); if (a == "test") { return true } else { alert("No match. Try again.") } return false } </script> </body>

Assuming that you don't have access to a backend app server, or that you don't want to use it for this, you can do something like假设您无权访问后端应用程序服务器,或者您不想为此使用它,您可以执行类似的操作

 document.getElementById("name").addEventListener("input", function(e) { var val = e.target.value; var form = e.target.closest("form"); //test.com/test1/test1.html form.action = "http://test.com/" + val + "/" + val + ".html"; console.log("action: " + form.action); });
 <form> <input name="name" id="name" /> <input type="submit"> </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM