当使用 Disqus anchor 链接(例如 url-to/my-blog-post#disqus_thread)访问我的博客 url 时,浏览器不会向下滚动到 <div id="disqus_thread">
元素。
相反,如果我已经在 url-to/my-blog-post 页面上,然后单击指向 url-to/的链接my-blog-post#disqus_thread 它向下滚动到 div
。
我以为是加载问题。浏览器访问页面并没有找到 div
元素,因为它仍然是由 Disqus JS 生成的。
我试图改变 JS 代码的位置,但没有任何改变。
这是我博客中的示例帖子网址: https://2bluebuffalo-en.blogspot.com/2018/11/how-to-crop-square-video-macos.html#disqus_thread 它不起作用,但如果您单击“By Blue Buffalo”旁边的链接(在共享按钮上方,现在写着“2 条评论”), anchor 链接就可以使用。
解决方法
好的,这就是我找到的解决方法。它工作得很好。以防万一有人要点击该链接。
<script>
setTimeout(function(){
var hash = window.location.hash.substr(1);
if (hash == "disqus_thread") {
location.hash = "#comments";
location.hash = "#" + hash;
};
}, 1000);
</script>
等待是因为它需要我一秒钟。加载所有内容(有时甚至更多)。它是可以改变的。
最佳答案
你可以试试这个技巧:
编辑博客的 HTML 并添加 Disqus 脚本。对于您的评论,您可以这样做:
<div id = "comments">
<div id = "disqus_thread"></div>
</div>
这会将您带到评论部分并加载 Disqus 评论。
关于javascript - Disqus anchor 链接 “#disqus_thread” 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54252716/