开发者

How to get the URL strings with subsites/subfolders only

I want to get the current URL using javascript/jquery. The URL should include subfolders/subsites in the path but not the page or any other query parameters.

Examples

http://test.com/site1/folder/abc/test.aspx

Output : http://test.com/site1/folder/abc/


http://test.com/site1/folder/abc/test.aspx?id=1&name=xyz

Output : http://test.com/site1/folder/abc/


http://test.com/site1/folder/abc/test.aspx?id=1,name=xyz

Output : http://test.com/site1/folder/abc/


http://test.com/site1/folder/abc/?testid=45

Ou开发者_如何学Pythontput : http://test.com/site1/folder/abc/

Any ideas?


demo

just javascript will do...

var str = "http://test.com/site1/folder/abc/?testid=45";    
str.slice(0,str.lastIndexOf('/')+1); // prints http://test.com/site1/folder/abc/

to get the current URL,

var str = window.location.href;    
str.slice(0,str.lastIndexOf('/')+1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜