简体   繁体   English

你如何加载一个单独的.html页面和Javascript

[英]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.

相关问题 如何加载2个可能在它们之间具有公共变量的javascript文件并在HTML页面上访问它? - How do you load 2 javascript files that could have common variables between them and accessing it on a HTML page? 如何使用 javascript 在单独的 html 页面上显示答案? - How do I display an answer on a separate html page using javascript? 您如何获得秒数来开始使用JavaScript进行页面加载 - how do you get seconds to start on page load using JavaScript 如何在点击时将单独的html页面加载到div中? - How to load separate html page into a div on click? 如何使用Javascript获取HTML页面的标题 - How do you get the title of an html page in Javascript 如何在页面加载时预加载Javascript编写的HTML? - How do I preload HTML that is written by a Javascript on page load? 如何使用 JavaScript 在 div 中加载 HTML 页面? - How do I load an HTML page in a div using JavaScript? 如何在JavaScript中加载HTML页面 - How to load a html page in javascript 如何创建由单独的Javascript生成的数据填充的弹出式HTML - How do you create a popup html populated with data generated from a separate Javascript 从一个项目中选择一个项目时,如何加载新的html页面 <select> html元素 - How do you load a new html page when select an item from a <select> html element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM