我想让此代码重定向到另一个页面,当人员输入hello时。我该怎么办? 如何在javascript中为我的html网站设置密码
<p>Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var person = prompt("Please enter your password");
if (person == hello) {
window.open("http://www.w3schools.com");
}
else {
confirm("Invalid Password")}
}
</script>
</body>
</html>
问题与标题完全无关。 – Scott
使用javascript(或任何客户端脚本)来控制密码访问通常是一个非常糟糕的主意。您可能不太安全的唯一方法是直接在页面上打印密码供所有用户查看。 – nomistic
这只是一个实验密码项目 –