If you need a full URL, for example. http://website/basedirectory/workingdirectory/ use:
var location = window.location.href; var directoryPath = location.substring(0, location.lastIndexOf("/")+1);
If you need a local path without a domain, for example. /basedirectory/workingdirectory/ use:
var location = window.location.pathname; var directoryPath = location.substring(0, location.lastIndexOf("/")+1);
If you don't need the slash at the end, delete +1 after location.lastIndexOf("/")+1 .
If you only need the name of the current directory in which the script is running, for example. workingdirectory use:
var location = window.location.pathname; var path = location.substring(0, location.lastIndexOf("/")); var directoryName = path.substring(path.lastIndexOf("/")+1);
flavio.donze Apr 05 '16 at 7:57 2016-04-05 07:57
source share