最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Load events for embedded elements - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Feb 20, 2021 at 15:19 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Apr 11, 2009 at 22:08 GeuisGeuis 42.3k57 gold badges163 silver badges223 bronze badges 2
  • 1 document.addEventListener('load',foo,false); ain't it work? – sepehr Commented Apr 11, 2009 at 22:23
  • in IE we have to use "attachEvent", I think. – sepehr Commented Apr 11, 2009 at 22:24
Add a ment  | 

5 Answers 5

Reset to default 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.

try

$("embed").ready(function(){ ... });

could always set like this:

document.getElementById("objectId").onload = function(){ ... }

jQuery is perhaps the best way to go with this.

$("embed").load(function(){
   // enter code here
})

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.

发布评论

评论列表(0)

  1. 暂无评论