[英]How can I find the current html filepage name using Javascript, on a LIVE-SERVER
I am going to deploy this page on an FTP And I need to find out how I can detect the html file currently being viewed using JavaScript. 我将在FTP上部署此页面,并且需要了解如何检测使用JavaScript当前正在查看的html文件。
If I open the html file, it works just fine with this: 如果我打开html文件,则可以正常使用:
var fileName = location.href.substring(location.href.lastIndexOf("/") +1);
But, if I open it via my localhost adress, it has a null value. 但是,如果我通过本地主机地址打开它,则它的值为空。 So I'm guessing I have to use some other method to extract the current html file name.
所以我想我必须使用其他方法来提取当前的html文件名。 Or is there a better approach to this?
还是有更好的方法呢?
Note: I am not going to use JQuery or anything like that. 注意:我不会使用JQuery或类似的东西。 EDIT: I can get the filename if it isn't my index file.. If it's the index file I get nothing using the above code.
编辑:如果不是我的索引文件,我可以得到文件名。如果是索引文件,则使用上面的代码我什么也没得到。 Most likely since all I have in my adress bar is the localhost adress of the live-server?
由于我地址栏中的所有内容很可能是实时服务器的localhost地址?
The web deals in URLs, not file names. 网络处理的是URL,而不是文件名。
Sometimes a URL will include something that looks like a file name, and sometimes that even maps on to a real file name on the server's hard disk. 有时,URL会包含类似于文件名的内容,有时甚至会映射到服务器硬盘上的真实文件名。
When you type http://example.com/
then it might map that onto a file called index.html
. 当您输入
http://example.com/
它可能会将其映射到名为index.html
的文件中。 Or maybe on to index.php
. 或者也许进入
index.php
。 Or maybe it won't touch any file but will just use logic built into the web server application to determine what to respond with. 也许它不会触摸任何文件,而只会使用Web服务器应用程序中内置的逻辑来确定响应的内容。
There's no way to know in the general case. 在一般情况下,没有办法知道。
If your specific case, you know that the path /
maps onto index.html
, so you can write an explicit mapping in your JavaScript code. 如果您是特定情况,则知道路径
/
映射到index.html
,因此可以在JavaScript代码中编写一个显式映射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.