2016-11-10 102 views
0

首先,我只想说我对html不太好,我所知道的关于html的所有内容都来自我自己在线学习的东西。如果条件为真,则将用户重定向到另一个html页面

所以..我有一个项目,其中一部分是制作一个网站。我已经做了网站,但我有一个问题..

我的问题是我不想让用户访问该设置,我希望管理员只能访问该设置,我通过将密码设置页面..所以如果用户点击设置图标,它会要求输入密码,如果其正确,那么用户可以去设置页面

我有3页(index.html,这是我的主页) ,(我的设置代码所在的manager.html)以及(index4代码所在的位置) in index.html有一个代码,让用户转到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语句'中使用它。 当我做了检查元素,我得到了这个错误“意外的令牌”<'“

有人可以告诉我如何纠正我的错误。

+0

你不能在一个JavaScript块中使用HTML ....'location'是你需要检查什么 –

回答

1

尝试设置document.location.href - 更多对here

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

2

另一种方式是作为波纹管使用。勾选此link

例如:

// 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"; 
相关问题