javascript - Javascript:无限滚动后更新文档
问题描述
在可无限滚动的页面上,文档元素不会反映附加到页面底部的新内容。
console.log(document.body.innnerHTML); // prints the document on initial page load
var scrollingElement = (document.scrollingElement || document.body);
scrollingElement.scrollTop = scrollingElement.scrollHeight;
console.log(document.body.innnerHTML); // does not print document with new content
PS:
可测试https://news.google.com/
解决方案
我在这里有几点说明为什么您的调查可能是错误的,而不是它的结果:
- 您在 innerHTML 中有一个错字(一个
n
太多了) 您可能只是没有看到代码中发生变化的那部分,但它就在那里。如果你这样做:
const x = document.body.innerHTML; document.scrollingElement.scrollTop = document.scrollingElement.scrollHeight; console.log(x == document.body.innerHTML);
你可以看到这是
false
- https://news.google.com/似乎不能无限滚动。至少不是我如何使用它。总之,
2.
显示有区别
推荐阅读
- javascript - 等待其他函数以构造函数结束
- c# - C#在不打开浏览器的情况下打开不和谐链接
- excel - 需要建议:VBA,从 BOM 中收集范围以一次更改多行的格式
- c++ - 错误“对‘doParsimPacking’的调用不明确”和“对‘doParsimUnpacking’的调用没有匹配函数”
- javascript - 反应错误:错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)
- sql - 编号取决于sql中的属性
- typescript - 如果 JSX 标签不为空,为什么 TypeScript 会忽略 JSX 传播 props 的类型?
- python - 替换 Pandas 列中的有限值
- android - 如何将五个图像序列传递给android中的tflite模型
- c# - 是什么导致了这个 NullReferenceException?- 统一 C#