[英]How do you load a separate .html page with Javascript
I am trying to figure out how to send a user to another page I design after they have input the correct password.我试图弄清楚在用户输入正确密码后如何将用户发送到我设计的另一个页面。 I don't know how to load the page with a JavaScript Command.
我不知道如何使用 JavaScript 命令加载页面。 How could i use the code below to open a new page titled insideVault.html?
我如何使用下面的代码打开一个名为 insideVault.html 的新页面?
I have tried many google searches, but cant find any resources to help me out with this.我已经尝试了很多谷歌搜索,但找不到任何资源来帮助我解决这个问题。
// login code //
<div class = "container">
<div class = "passwordEnter">
<div class = "text-center">
<form id="login" onsubmit="return passCheck()" method="get">
<p> Enter Password </p>
<input type="password" name="password" id = "password">
<input type="submit">
</form>
</div>
</div>
</div>
<script src="script.js"></script>
</div>
<script>
function passCheck(){
var input = document.getElementById("password").value == 'test';
console.log(input);
if(!input){
alert('Password incorrect, please try again.');
return false;
}
return true;
}
I want the code to load a new page, but so far I have not been able to find any code that would allow me to do this.我希望代码加载一个新页面,但到目前为止我还没有找到任何可以让我这样做的代码。
Try location.href
:尝试
location.href
:
function passCheck(){
var input = document.getElementById("password").value == 'test';
console.log(input);
if(!input){
alert('Password incorrect, please try again.');
return false;
}
location.href = 'insideVault.html';
}
In Javascript, you can use many methods to redirect a web page to another one.
在 Javascript 中,您可以使用多种方法将 web 页面重定向到另一个页面。 Almost all methods are related to window.location object, which is a property of the Window object.
几乎所有方法都与 window.location object 有关,这是 Window ZA8CFDE6331BD59EB2AC96F8911 的属性It can be used to get the current URL address (web address) and to redirect the browser to a new page.
可用于获取当前的 URL 地址(网址),并将浏览器重定向到新页面。
Example:例子:
<html>
<head>
<script>
function newLocation() {
window.location="http://www.w3.org";
}
</script>
</head>
<body>
<input type="button" value="Go to new location" onclick="newLocation()">
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.