I am trying to implement what seems to be very simple JavaScript redirection, via the following rudimentary command:
window.location.href = "http://www.somesite.com";
So far so good, it works. I also can do it via the following method:
location.replace("http://www.somesite.com");
No problem here, it works again! The problem comes when I loose the protocol out of the string:
window.location.href = "www.somesite.com";
OR:
location.replace("www.somesite.com");
It just appends the new location to the current url:
http://www.currentsite.com/www.somesite.com
Of cause, that’s not what I want. Is there any way to force the redirect?
One way is to use protocol-relative url like this:
Or
This way, it would redirect and browser itself will take care of figuring out protocol part eg
httporhttpsWorking Example