My javascript code ,
var docPath = document.location.pathname.toString()
returns
/myFolder/UserControls/myUserControl.ascx
I want to subString likes
/myFolder/UserControls/
How can I do it ?
Mhh..
var n=str.lastIndexOf("/"); // get the last "/"
var result = str.substring(0, n); // only keep everything before the last "/" (excluded)
Does what you want ?
You can use the match string method:
var fullPath = '/myFolder/UserControls/myUserControl.ascx';
var path = fullPath.match(/(.+\/)/);
alert(path[1]); // This will output "/myFolder/UserControls/"
You can verify the working at the following JSFiddle: http://jsfiddle.net/H5PGb/
Your question is no very much clear. You may try
var docPath = document.location.pathname.toString()
.substring(0,document.location.pathname.toString().lastIndexOf("/")+1);