我似乎找不到与此类似的问题,因此非常感谢重定向。我的问题:我已经将以下 Javascript 插入到我的网站的页脚中,但是,时间戳并没有出现在主页的底部,而是到处弹出...导航栏中的一些链接不t 链接到一个页面,而是链接到时间戳。 (即关于 > 版本控制 = 呈现上次修改日期)。我如何将它锚定到主页的页脚?
感谢您的帮助!
网站:www.huondauvergne.org
脚本:
var m = "This page was last updated: " + document.lastModified;
var p = m.length-8;
document.writeln("<center>");
document.write(m.substring(p, 0));
document.writeln("</center>");
最佳答案
选项 1:
将您的时间戳编写代码包装在检查当前 url 路径的 if 中。
因此,如果您的主页位于 www.abc.com,您可以这样做
if (location.pathname == '/') {
// Insert timestamp writing code here
}
如果它在 www.abc.com/index.html,你会这样做
if (location.pathname == '/index.html') {
// Insert timestamp writing code here
}
基本上,您的主页与域相关的位置就是您要检查的位置。
选项 2:
在主页上插入时间戳的 Javascript:
HTML:
<footer>
<!-- Footer stuff -->
<span id="lastModified"></span>
</footer>
主页上的 Javascript/jQuery:
$(document).ready(function () {
$("#lastModified").text('Last modified on ' + lastModified);
});
关于javascript - 主页最后修改日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46961666/