If I do an online onload
event for embedded objects, that seems to work but I can't seem to get the load
event working through addEventListener
. Is this expected?
Asked
Active
Viewed 2.3k times
11

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

Geuis
- 41,122
- 56
- 157
- 219
-
1document.addEventListener('load',foo,false); ain't it work? – sepehr Apr 11 '09 at 22:23
-
in IE we have to use "attachEvent", I think. – sepehr Apr 11 '09 at 22:24
5 Answers
3
Probably, but it may be browser dependent.
windows and images and iframes define their load events with addEventListener and attachEvent, but other load events are browser specific.
A script or link element's onload doesn't attach in IE, for instance.

kennebec
- 102,654
- 32
- 106
- 127
-1
could always set like this:
document.getElementById("objectId").onload = function(){ ... }
-
@Geuis already said that works. They are wondering why `addEventListener` doesn't work. – strager Aug 13 '10 at 04:28
-2
jQuery on/bind/load
won't be fired for embed elements, while ready
works but not after rendered when using Chrome, if you want to listen to the stage after rendering embeded elements, you may have to use pure js to add handlers.

PuiMan Cheui
- 94
- 1
- 9
-2
jQuery is perhaps the best way to go with this.
$("embed").load(function(){
// enter code here
})

jackyalcine
- 469
- 1
- 8
- 21
-
Interesting. Might be my fault, I wasn't 100% sure if `load` was an event to the `embed` element. – jackyalcine Dec 12 '12 at 15:52
-
@clarkk: Interesting, but isn't that method different in implementation depending on the version of jQuery one uses? – jackyalcine Nov 12 '14 at 18:19