开发者

Retrieving file name with Javascript (without URL?)

开发者 https://www.devze.com 2022-12-16 16:15 出处:网络
I need to retrieve the file name of an HTM file - the file needs to retrieve its own file name - to use in another Javascript function within the same file. So far I have -

I need to retrieve the file name of an HTM file - the file needs to retrieve its own file name - to use in another Javascript function within the same file. So far I have -

var Docname = "ESSA_CL_2009_01"
var DSstem = new Spry.Data.XMLDataSet("ESSA10_DA_sour开发者_StackOverflow社区ceData_19_1.xml", "ESSA_CL_2009/" + Docname + "/Item_stem");

(the Spry or AJAX stuff is already set up)

The var Docname I'd like to be generated dynamically. It doesn't have a URL yet as such - I don't have any control over its final destination.

Any help would be much appreciated. Thanks.


If the "Docname" refers to the current page's static file path, then you can use document.location.pathname to get the pathname portion of the URL, and then parse that as a string to grab only the portion you desire.


var getFileName = function (uri) {
  var fileName = uri.substr(uri.lastIndexOf("/") + 1);
  return fileName.substr(0, fileName.lastIndexOf("."));
};
0

精彩评论

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

关注公众号