onLoad 到底何时发生

发布于 2024-10-18 05:40:45 字数 376 浏览 5 评论 0原文

我特别关心 DOM 选定元素的 onload 事件。出于示例目的,假设我的 DOM 中有一个图像。

正如我认为我所理解的那样,当图像绘制到屏幕上时,应该触发该图像的 onload 事件,但最近我得到的数据表明并非如此。所以我的问题如下:

按照以下事件的顺序,图像的 onload 事件何时触发?

  1. 检查包含图像的 HTML
  2. 对图像发出请求 收到图像的
  3. 第一个字节 收到
  4. 最后一个字节
  5. 浏览器检查 HTTP 响应的标头
  6. 图像被绘制到屏幕上

我特别关心 Firefox,但我也会感兴趣这如何影响 Internet Explorer(特别是 IE8)和 Chrome

I am specifically concerned with the onload event for selected elements of the DOM. For the purpose of example assume there is an image in my DOM.

As I thought I understood it, the onload event for this image should fire when the image is drawn to the screen, but recently I've been given data to suggest otherwise. So my question is as follows:

When, in the order of the following events, does the onload event for an image fire?

  1. HTML containing the image is examined
  2. Request is made for the image
  3. First Byte is received for the image
  4. Last Byte is received
  5. Browser examines the header of the HTTP response
  6. Image is drawn to the screen

I am specifically concerned with Firefox, but I would also be interested in how this affects Internet Explorer (specifically IE8) and Chrome

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

醉南桥 2024-10-25 05:40:45

加载事件发生在屏幕上绘制图像之后

演示: http://jsfiddle.net/e5hvr/

(警报会阻止浏览器线程,因此如果尚未绘制图像,则在警报仍打开时您将无法看到它。)

The load event occurs after the image has been drawn on the screen.

Demo: http://jsfiddle.net/e5hvr/

(The alert blocks the browser thread, so if the image hadn't been drawn already, you wouldn't be able to see it while the alert is still open.)

静待花开 2024-10-25 05:40:45

根据 jQuery 文档

虽然 JavaScript 提供了负载
当页面出现时执行代码的事件
被渲染,这个事件没有得到
触发直到所有资产,例如
图片已完全收到。

因此,为了回答你的问题,我会在你列出的所有事件之后说。

Per the jQuery docs

While JavaScript provides the load
event for executing code when a page
is rendered, this event does not get
triggered until all assets such as
images have been completely received.

So, to answer your question, I would say after all of the events you listed.

烟雨扶苏 2024-10-25 05:40:45

我会说除了 6 之外的所有。当然,你的事件顺序是错误的;标题位于数据之前。

I would say all but 6. And your events are in the wrong order, of course; the headers come before the data.

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