window.load doesn't fire always on chrome?

前提是你 提交于 2019-11-28 12:45:30

The cause of the problem is that the Content script is sometimes executed when the document has already fully loaded. This is illustrated using the following Content script ("User Script"):

// ==UserScript==
// @name          Test
// @namespace     Test
// @include       *
// ==/UserScript==

window.addEventListener('load', function(){alert("loaded");}, false);
alert(document.readyState);   // When this prints "complete", onload never runs

To solve the issue, use the @run-at document-start meta-rule, which causes the script to execute before the document is created:

...
// @run-at   document-start
// ==/UserScript==

This call may be being loaded too late on the page. Add this code to the very top of the page and see if that fixes it.

If that isn't it please post some additional information. (Where the call is being made? Some more information on the page? Is this being called from an external .js file?)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!