在Opera's用户js中,当页面完成加载并下载了所有资源(如img,script,css等)时,使用什么事件名

What event name use in Opera's userJS to trigger a function when page finished loading and has downloaded all its assets like img,script,css etc.?

本文关键字:img script css 资源 什么 事件 下载 用户 js Opera 加载      更新时间:2023-09-26

这是我的代码:

document.addEventListener('load', function () {
  alert(document.getElementsByTagName("DIV").length);
}, false);
//'load' event above doesn't show any response, alert isn't showing
alert(document.getElementsByTagName("DIV").length);
// this alert returns 0 it looks like it is called before the page DOM has loaded
window.onload = function() {
 alert(document.getElementsByTagName("DIV").length);
};
//returns 0, what the... it seems DOM hasn't loaded also
// but only on some sites, here on stackoverflow and youtube it works,
//but on google.com and many other websites (pcworld.com) shows 0

在最新的稳定版和alpha版opera中也是如此。

我建议你直接做

window.addEventListener('load', function(){}, false)

就像在正常脚本中一样。您可以使用opera.addEventListener('BeforeEvent.load', ...),但如果页面的脚本在某些Opera版本中不侦听加载事件,则可能不会触发。

其他一些背景阅读:窗口。Onload vs document.onload

addEventListener("input", callback)在opera中不工作?