Reputation: 4370
Suppose I'm on this page:
http://example.com/users/BECCA/edit/advanced
I want to redirect the user to:
http://example.com/users/BECCA/edit
How can I do this?
(I'm also familiar with window.history.back();
but my question is something else!)
Thanks.
Upvotes: 0
Views: 84
Reputation: 2492
The first answer is right but just have one problem, it does't work for http://example.com/
So the better code should be this:
var url = location.href.split("/");
if(url.lenght == 3){
//the url is http://example.com/ do what ever you want
}
else{
location.href=url.slice(0,-1).join("/");
}
Upvotes: 0
Reputation: 18995
/
/
as delimiterlocation.href=location.href.split("/").slice(0,-1).join("/");
Upvotes: 1