如何查看哪些元素仍在加载并阻碍 window.onload 触发?
有没有办法查看网站的哪些元素仍在加载,以便 window.onload 无法触发?
is there a way to see which elements of a website are still loading so that window.onload can't fire yet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道有什么全球性的方法可以做到这一点——很可能没有。
唯一想到的就是 检查图像是否已成功加载。我想您可以浏览每个图像并检查这些属性。
但是,您将很难区分失败的图像加载过程和那些仍在进行的。为了进行这种区分,您必须使用每个图像的
onerror
事件并设置某种“失败”标志。真正非常困难的是控制缓慢加载的脚本:如果脚本加载缓慢,则此时不会执行 JavaScript,因此除了使用
asnyc
或deferproperties
...但我想这需要对你正在使用的任何 JavaScript 进行根本性的改变。
I don't know of a global way of doing this - it could well be there is none.
The only thing in that vein that comes to mind is checking images for whether they have successfully loaded. I guess you could walk through each image and check for those properties.
However, you will be having a hard time to tell apart failed image load processes and those still under way. To make that distiction, you would have to work with the
onerror
event for each image and set some sort of "failed" flag.What is going to be really, really hard is controlling slowly loading scripts: If a script loads slowly, there is no execution of JavaScript for that moment, so there is no way to detect any delays here except by using the
asnyc
ordefer
properties... But I guess that would require fundamental changes to whatever JavaScript you are using.我不这么认为,但如果您不想等到所有图像加载完毕,您可以使用 domready-函数
i don't think so, but if you don't want to wait till all images are loaded, you can use a domready-function
Firebug 中的网络选项卡可能会帮助您。
The network-tab in Firebug might help you.