【发布时间】:2015-09-24 02:13:27
【问题描述】:
我想用 javascript 显示用户所在页面的文件名。例如,
https://test.example.com/wow.html
应该返回
wow
我尝试使用replace() 方法,如下所示:
var url = document.URL;
document.getElementById("code").innerHTML = url.replace("http://test.example.com/", " ");
但我不知道如何删除 .html 扩展名,或者也替换 https 网址。有没有更好的方法来做到这一点?
谢谢。
【问题讨论】:
-
替换后你可以做一个
substring到indexOf.html
标签: javascript url replace