在javascript中,有没有办法知道当前加载的文件名是什么?
例如我有文件名index.html、history.html、favorites.html。我想根据这些加载的文件执行一些条件逻辑。
有没有办法在 JavaScript 中做到这一点?
最佳答案
var url = window.location.pathname;
var filename = url.substring(url.lastIndexOf('/')+1);
alert(filename);
关于javascript - 我如何知道当前加载的文件名是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50998141/