views:

223

answers:

2

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_sourceData_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.

+1  A: 

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.

Ed Schembor
Thanks.. um - there won't be a static file path: The final destination location of the file will be different and is unknown.. Using var url=document.URL would seem to be be the right way to go as an initial line of code, rather than pathname (?) - but it doesn't work either .. (I did try var url=document.location.pathname;)
andrew
A: 
var getFileName = function (uri) {
  var fileName = uri.substr(uri.lastIndexOf("/") + 1);
  return fileName.substr(0, fileName.lastIndexOf("."));
};
Eli Grey