Check if iframe is loaded inside $ (document) .ready

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

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

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

Any idea why this is happening?

Thanks.

+4
source share
3 answers

Try this instead.

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

When working with iFrames, it is enough to use the load() event instead of the $(document).ready() event.

+14
source

This is because you are checking if the iFrame is ready, and not inside the document.

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

gotta do the trick.

+1
source

I tried:

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

and it did not work for me.

this is:

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

Even though the event does not fire so quickly, it waits for the images and css to load.

0
source

Source: https://habr.com/ru/post/1485623/


All Articles