开发者

DOMContentLoaded is not getting triggered while visiting few sites. Any workaround?

开发者 https://www.devze.com 2023-03-28 09:35 出处:网络
I am developing a Firefox extension. My extension needs to get notified when a page completes loading. To implement this I am using DOMContentLoaded event. This works fine most of the times. But while

I am developing a Firefox extension. My extension needs to get notified when a page completes loading. To implement this I am using DOMContentLoaded event. This works fine most of the times. But while visiting few sites (like nytimes.com), this event is not getting tri开发者_开发技巧ggered at all. I am not sure whether these sites are using some special scripts.

Is there any workaround for this? Or is there a better way to implement what I am trying to do?


DOMContentLoaded may not be what you need...

According to MDN

Fired at the page's Document object when parsing of the document is finished. By the time this event fires, the page's DOM is ready, but the referenced stylesheets, images, and subframes may not be done loading; use the "load" event to detect a fully-loaded page.

https://developer.mozilla.org/en/Gecko-Specific_DOM_Events

So, it is possible that nytimes.com and others my be using frames or complex CSS and that is why you are not getting the correct trigger.

As mentioned above, the "fix" is to

use the "load" event to detect a fully-loaded page

0

精彩评论

暂无评论...
验证码 换一张
取 消