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

javascript - Check if iframe is loaded inside $(document).ready - Stack Overflow

programmeradmin3浏览0评论

I want to check if iframe is loaded with the following code:

$(document).ready(function() {
    jQuery('#iframeID').ready(somefunction);
}

It seems that 'somefunction' is called before iframe is loaded (the iframe is empty - just empty html-head-body).

Any idea why this happens?

Thank you.

I want to check if iframe is loaded with the following code:

$(document).ready(function() {
    jQuery('#iframeID').ready(somefunction);
}

It seems that 'somefunction' is called before iframe is loaded (the iframe is empty - just empty html-head-body).

Any idea why this happens?

Thank you.

Share Improve this question asked Jun 11, 2013 at 13:42 Uros KUros K 3,3844 gold badges32 silver badges46 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 15

Try this instead.

$('#iframeID').load(function() {
    callback(this);
});

While dealing with iFrames, it is good enough to use load() event instead of $(document).ready() event.

This is because you're checking if the iFrame is ready, not the document inside.

$(document.getElementById('myframe').contentWindow.document).ready(someFunction);

should do the trick.

I have tried:

$("#frameName").ready(function() {
    // Write you frame on load javascript code here
} );

and it did not work for me.

this did:

$("#frameName").load( function() {
     //code goes here
} );

Even though the event does not fire as quickly - it waits until images and css have loaded also.

发布评论

评论列表(0)

  1. 暂无评论