3

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 -->
Renoissance
  • 49
  • 1
  • 8

2 Answers2

1

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
  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"
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • It does work but it doesn't redirect, instead it shows that it is being canceled on the networks tab. Here's the screenshot. https://snipboard.io/uegXRi.jpg – Renoissance Mar 28 '21 at 10:04
  • What is the file you want to load? I see `check` is that a directory? If so, is directory browsing turned on? – mplungjan Mar 28 '21 at 10:24
  • check is a php file. I add php on the end of the file at the code just to make sure. – Renoissance Mar 28 '21 at 10:25