Reputation: 905
I do window.location.replace = window.location.hostname + '/something'
in myexample.com/page, it will become myexample.com/page/myexample.com/page/something
How to do a full redirect?
Upvotes: 0
Views: 1062
Reputation: 1871
Use window.location.href
, which is the current location of the window.
To be sure, check if the last character is a /
.
var current = window.location.href;
var append = current.slice(-1) === '/' ? 'something' : '/something';
window.location = current + append;
More info: https://developer.mozilla.org/en-US/docs/Web/API/Window/location
Upvotes: 1