如何查看哪些元素仍在加载并阻碍 window.onload 触发?

发布于 2024-09-02 03:46:34 字数 48 浏览 13 评论 0原文

有没有办法查看网站的哪些元素仍在加载,以便 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哆兒滾 2024-09-09 03:46:35

我不知道有什么全球性的方法可以做到这一点——很可能没有。

唯一想到的就是 检查图像是否已成功加载。我想您可以浏览每个图像并检查这些属性。

但是,您将很难区分失败的图像加载过程和那些仍在进行的。为了进行这种区分,您必须使用每个图像的 onerror 事件并设置某种“失败”标志。

真正非常困难的是控制缓慢加载的脚本:如果脚本加载缓慢,则此时不会执行 JavaScript,因此除了使用 asnycdeferproperties...但我想这需要对你正在使用的任何 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 or defer properties... But I guess that would require fundamental changes to whatever JavaScript you are using.

擦肩而过的背影 2024-09-09 03:46:35

我不这么认为,但如果您不想等到所有图像加载完毕,您可以使用 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

蓝海 2024-09-09 03:46:35

Firebug 中的网络选项卡可能会帮助您。

The network-tab in Firebug might help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文