如果条件为真,将用户重定向到另一个html页面 [英] redirect user to another html page if the condition is true
问题描述
首先,我只想说我对html不好,我对html的了解仅来自我自己在网上学到的东西.
First of all, I just want to say that I'm not good with html, all i know about html is from what i learn online by myself.
所以..我有一个项目,其中一部分是建立网站.我已经建立了网站,但是遇到了问题.
So.. I have a project and part of it is making a website. I already made the website but i have a problem..
我的问题是我不想让用户访问该设置,我希望管理员仅访问该设置,我是通过在设置页面中输入密码来实现的. ,它将要求输入密码,如果密码正确,则用户可以进入设置页面
My problem is I don't want to let the user access the setting, I want the admin to only access the setting, I did that by putting a password in setting page.. so if the user clicks on the setting icon, it will ask for a password, if its correct then the user can go to setting page
我有3页(index.html是我的主页),(manager.html是我的设置代码所在的位置)和(index4是该代码所在的位置) 在index.html中,有一个代码可以使用户转到index4.html页面 并且在index4.html页面中是此代码
I have 3 pages (index.html which is my home page),(manager.html where my setting code is in) and (index4 where this code is in) in index.html there a code which let the user go to index4.html page and in index4.html page is this code
<!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'中,则似乎无法使用它. 当我检查元素时,出现此错误意外令牌'<'"
From what I learn online, href="link" code can redirect to another page.. but it seems I can't use it if it's in 'if statement'. when I did inspect element,I got this error "Unexpected token '<'"
有人可以告诉我如何纠正我的错误吗?
Can someone please tell me how to correct my mistake.
推荐答案
另一种方法是用作波纹管.选中此链接
Another way is to use as bellow. Check this 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";
这篇关于如果条件为真,将用户重定向到另一个html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!