在 DOMContentLoaded 之前触发的事件
在我的 Firefox 扩展中,我使用 DOMContentLoaded 来检测页面加载并插入 HTML。是否有在此之前触发的事件并且该文档当时仍然可用?
In my Firefox extension I am using DOMContentLoaded
to detect page load and insert my HTML. Is there an event which triggers before this and still the document is available at that time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:此答案指的是基于 XUL 的扩展。从 Firefox 57 开始,该技术已过时。此处提到的功能不再可供扩展使用。
有一个
content-document-global-created
通知在创建文档时,在添加任何内容之前发送出去(准确地说,当浏览器收到响应的 HTTP 标头并知道它不是重定向等时,就会发生这种情况)。这是您可以获取该文档的最早时间点。一旦 Gecko 完成下载文档内容,就会触发DOMContentLoaded
事件,这是您可以访问完整 DOM 的早期点。中间还有很多其他事件,例如很多 进度侦听器事件 - 其中您使用哪个取决于您想要做什么,没有通用答案。Note: This answer refers to XUL-based extensions. As of Firefox 57, this technology is obsolete. The functionality mentioned here is no longer available to extensions.
There is
content-document-global-created
notification that is sent out when a document is created, before any content is added to it (to be precise, it happens when the browser receives the HTTP headers of the response and knows that it isn't a redirect or such). That's the earliest point where you can get the document. TheDOMContentLoaded
event is fired once Gecko finishes downloading the contents of the document, that's the earlies point where you can access the complete DOM. In between there is a bunch of other events, e.g. lots of progress listener events - which one you use depends on what you are trying to do, there is no general answer.