开发者

Using .live() for iFrame.load() event?

开发者 https://www.devze.com 2023-03-26 06:34 出处:网络
I know an iFrame is added to my page via javascript somewhere in my page, I want to be notified when it is loaded, but this doesn\'t 开发者_开发技巧work:

I know an iFrame is added to my page via javascript somewhere in my page, I want to be notified when it is loaded, but this doesn't 开发者_开发技巧work:

$("iframe").live("load",
    function () {
        alert(this.name + ": Im loaded!");
    });

No alert is shown

Any idea why? any idea how can we achieve this?


I think you can do a callback after adding the iframe to your page. As mentioned here, it's not possible to bind live() to iframe load().

Note: The .live() and .delegate() methods cannot be used to detect the load event of an iframe. The load event does not correctly bubble up the parent document and the event.target isn't set by Firefox, IE9 or Chrome, which is required to do event delegation.

So in your callback, you have to call this, maybe set a timeout to make sure it fires after the iframe has been loaded.

$("iframe").load(function () {
    alert(this.name + ": Im loaded!");
});


It won't work, for load event only works on Window object.

If you wish to be noticed when page inside the iframe is loaded, then you should write code on the inside page, which calls window.parent to notify its parent page.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号