完整网址
如果您想要完整的URL,例如,http://website/basedirectory/workingdirectory/使用:
var location = window.location.href;
var directoryPath = location.substring(0, location.lastIndexOf("/")+1);
本地路径
如果您想要没有域的本地路径,请/basedirectory/workingdirectory/使用:
var location = window.location.pathname;
var directoryPath = location.substring(0, location.lastIndexOf("/")+1);
如果您不需要在末尾使用斜杠,请删除+1after location.lastIndexOf("/")+1。
目录名
如果只需要当前目录名称(运行脚本的位置),例如,请workingdirectory使用:
var location = window.location.pathname;
var path = location.substring(0, location.lastIndexOf("/"));
var directoryName = path.substring(path.lastIndexOf("/")+1);