我想,让我们在index.htm上说这个:
<html>
<head>
<script type="text/javascript" src="javascriptfile.js"></script>
</head>
</html>
然后让该脚本返回 <title>index</title>
,并且索引根据文件名是动态的。我怎样才能做到这一点?
最佳答案
您确实应该在服务器端执行此操作。但如果您坚持客户端处理,这应该可行:
document.write('<title>' +
window.location.pathname.replace(/^(.*\/)?([^\/.]*).*$/, "$2") +
'</title>');
如果您确实采用这种方法,每次有人访问您的网站时,$DEITY 都会杀死一只小猫。
关于javascript - 如何将文档名称发送到 javascript 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4538242/