Reputation: 67
I have a situation where I need to get the current page url and redirect to a new page by adding to the current page url. For example:
http://www.mywebsite.com/page1/page2
needs to redirect to:
http://www.mywebsite.com/page1/page2/page3
I need it to be relative because "/page1/page2/" will always be different, but "page3" will always be the same.
I've tried: location.href = "./page3"; but that does not work. The result is: http://www.mywebsite.com/page1/page3
Any thoughts?
Upvotes: 0
Views: 87
Reputation: 11
Get and Set URL using either window.location.href
or document.URL;
window.location.href = window.location.href + "/page3";
Should do what you're looking for.
Upvotes: 0