繁体   English   中英

我怎样才能 go 到另一个 HTML 文件

[英]How Can I go to another HTML file

出于某种原因, document.location.hrefwindow.location.hrefwindow.location.replace无法正常工作,我现在使用的是 localhost,我不知道如何将其重定向到另一个网页。 我尝试在前面添加 http:// ,它仍然无法正常工作,我尝试将其重定向到另一个在线网站,它也没有工作。 我已经阅读了很多线程并尝试了它们,但它们都不适合我。

var loginBut = document.getElementById("RDbtn1");
loginBut.addEventListener("click", checklogin);
function check(){
    document.location.href =  "http://localhost/some/directory/here";
    alert(document.location.origin + '/some/directory');  // I just use this to know that the button is being pressed.

}

html:

  <!-- some code here-->
<li><button class="login1" id="RDbtn1">LOGIN</button></li>
  <!-- some code here -->

我相信您应该重定向到特定的 html 页面,并且应该提供本地主机应用程序正在运行的端口

document.location.href =  "http://localhost:8080/some/directory/here/file.html";
  1. 它是 window.location (nothing 或 replace 或 href) - document.location 通常用于获取实际页面

JavaScript 中的 window.location 和 document.location 有什么区别?

  1. 如果您在同一台服务器上,则无需限定页面,但我会添加您尝试加载的实际页面

window.location = "/some/directory/here/index.html"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM