简体   繁体   中英

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

  <!-- 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

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

What's the difference between window.location and document.location in JavaScript?

  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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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