0

This is my code:

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

The same situation in latest stable and alpha Operas.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
rsk82
  • 28,217
  • 50
  • 150
  • 240

1 Answers1

0

I suggest you simply do

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

like you would in a normal script. You could use opera.addEventListener('BeforeEvent.load', ...) but that might not fire if the page's scripts do not listen for load events in some Opera versions.

Some other background reading: window.onload vs document.onload

addEventListener("input", callback) doesn't work in opera?

Community
  • 1
  • 1
hallvors
  • 6,069
  • 1
  • 25
  • 43