Thomas Smyth Thomas Smyth - 1 month ago 7
Javascript Question

window.location.href not working as intended

I'm using a javascript along with php to create a login system for a project I'm working on.

I have everything working in regards to actually logging the user in and then checking this within my javascript, however when I redirect the user from the login page to a private page I'm having issues with window.location.href in the javascript.

I own the domain thomas-smyth.co.uk, so I have tried the following piece of code to redirect the user.

window.location.href = "http://thomas-smyth.co.uk/home.php";


However, when this redirects me it is redirecting me to thomas.smyth.co.uk, which obviously causes the page not to load. Any ideas on how I could fix this?

Thanks in advance,
Tom

Ben Ben
Answer

You have posted the wrong code. In your Js File thomas-smyth.co.uk/functions/login.js on your webserver is this:

//Re-directs to subdomain.
window.location.href = "http://www.thomas.smyth.co.uk/home.php";

this should be fixed to

//Re-directs to subdomain.
window.location.href = "http://thomas-smyth.co.uk/home.php";

@vlaz mentioned right, you have a second mistake with a wrong dot instead of a dash

And btw you should explain your problem a bit more. More code would be usefull next time if you want some help.