2012-11-14 22 views

回答

5

这里是一个可能的解决方案:

var result = url.substring(0, url.lastIndexOf("/")); 

这里是另一个(不是最好的,但是)解决方案:

var result = url.split("/").slice(0, -1).join("/"); 
-2

要获取当前窗口的网址,你可以使用: window.location.href;

广告从中提取一个子部分,直到您最后的/您可以使用以下脚本:

<script type="text/javascript"> 
var currUrl = window.location.href; 
var modUrl =currUrl.substring(0,currUrl.lastIndexOf("/")); 
//modUrl =currUrl.substring(0,currUrl.lastIndexOf("bbb")); //Incase you have some other criteria to extract the sub URL. 
</script> 

希望它有帮助。

相关问题