简体   繁体   English

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

[英]How Can I go to another HTML file

For some reason, document.location.href , window.location.href , and window.location.replace is not working, I'm using localhost for now and I don't know how to redirect it to another webpage.出于某种原因, document.location.hrefwindow.location.hrefwindow.location.replace无法正常工作,我现在使用的是 localhost,我不知道如何将其重定向到另一个网页。 I tried adding http:// on front, it's still not working, I tried making it redirect to another online website, It also didn't work.我尝试在前面添加 http:// ,它仍然无法正常工作,我尝试将其重定向到另一个在线网站,它也没有工作。 I read a lot of thread already and tried them but none of them worked for me.我已经阅读了很多线程并尝试了它们,但它们都不适合我。

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: html:

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

I believe you should redirect to particular html page and should give the port on which your local host application is working我相信您应该重定向到特定的 html 页面,并且应该提供本地主机应用程序正在运行的端口

document.location.href =  "http://localhost:8080/some/directory/here/file.html";
  1. It is window.location (nothing or replace or href) - document.location is normally used to get the actual page它是 window.location (nothing 或 replace 或 href) - document.location 通常用于获取实际页面

What's the difference between window.location and document.location in JavaScript? JavaScript 中的 window.location 和 document.location 有什么区别?

  1. If you are on the same server, no need to qualify the page but I would add the actual page you try to load如果您在同一台服务器上,则无需限定页面,但我会添加您尝试加载的实际页面

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

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

相关问题 如何在项目中将特定输入 go 输入到 another.html 文件中? - How do I make specific inputs go into another .html file in the project? 如何从 React 组件中的另一个文件呈现 HTML? - How can I render HTML from another file in a React component? 如何将JQuery和另一个JS文件链接到我的html? - How can I link JQuery AND another JS file to my html? 如何将数据从HTML表单传递到处理AJAX调用的JavaScript文件 - How can I go about passing data from a HTML form to a JavaScript file that handles AJAX calls 如何向该文件输入 go - How can I make an input go to that file 如何使用 XMLHttpRequest 在另一个 HTML 文件中显示 html 文件? - how can i display an html file in another HTML file using XMLHttpRequest? 如何将变量移至另一个html文件并根据该变量更改html文件上的文本 - How can I move a variable over to another html file and change the text on the html file based on the variable 通过JS转到另一个HTML文件 - Go to another html file via JS 我怎样才能使 HTML/NodeJS 表单根据响应转到另一个表单,有点像 Google 表单的“根据答案转到部分?” - How can I make an HTML/NodeJS form go to another form based on a response, sort of like Google Form's "Go to section based on answer?" 我如何使用angularjs转到另一个页面 - How can i go to another page using angularjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM