假设我在这个页面上:
http://example.com/users/BECCA/edit/advanced
我想将用户重定向到:
http://example.com/users/BECCA/edit
我该怎么做?
(我也熟悉window.history.back();
,但我的问题还不错!)
感谢。
答案 0 :(得分:1)
/
/
作为分隔符location.href=location.href.split("/").slice(0,-1).join("/");
答案 1 :(得分:0)
第一个答案是正确的,但只有一个问题,它确实适用于http://example.com/
所以更好的代码应该是这样的:
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("/");
}