![](/img/trans.png)
[英]How do you load 2 javascript files that could have common variables between them and accessing it on a HTML page?
[英]How do you load a separate .html page with Javascript
我试图弄清楚在用户输入正确密码后如何将用户发送到我设计的另一个页面。 我不知道如何使用 JavaScript 命令加载页面。 我如何使用下面的代码打开一个名为 insideVault.html 的新页面?
我已经尝试了很多谷歌搜索,但找不到任何资源来帮助我解决这个问题。
// 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;
}
我希望代码加载一个新页面,但到目前为止我还没有找到任何可以让我这样做的代码。
尝试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';
}
在 Javascript 中,您可以使用多种方法将 web 页面重定向到另一个页面。 几乎所有方法都与 window.location object 有关,这是 Window ZA8CFDE6331BD59EB2AC96F8911 的属性可用于获取当前的 URL 地址(网址),并将浏览器重定向到新页面。
例子:
<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.