使用 Javascript 检索文件名(没有 URL?)
我需要检索 HTM 文件的文件名 - 该文件需要检索其自己的文件名 - 以便在同一文件中的另一个 Javascript 函数中使用。到目前为止,我已经 -
var Docname = "ESSA_CL_2009_01"
var DSstem = new Spry.Data.XMLDataSet("ESSA10_DA_sourceData_19_1.xml", "ESSA_CL_2009/" + Docname + "/Item_stem");
(Spry 或 AJAX 的东西已经设置好)
我想动态生成 var Docname。它还没有 URL——我无法控制它的最终目的地。
任何帮助将不胜感激。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果“Docname”指的是当前页面的静态文件路径,那么您可以使用 document.location.pathname 获取 URL 的路径名部分,然后将其解析为字符串以仅获取您想要的部分。
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.