$(document).ready and iframe content [duplicate]

2019-01-27 16:44发布

问题:

This question already has an answer here:

  • jQuery .ready in a dynamically inserted iframe 9 answers

Will

$(document).ready 

in parent page wait for iframe content to be loaded completely?

I have a parent page in which there is a an iFrame. After the iFrame is completely loaded I need to invoke a function in the iFrame from the parent page.

回答1:

See jQuery .ready in a dynamically inserted iframe



回答2:

I've been the whole day breaking my balls to find this, I needed it for the work.

Finally I've made my thing (A website with an iframe that loads the content of the links. All i wanted to do was to scroll the page to the top, with a button inside the iframe And it seemed to be wizards work)

Well, that's what I did:

$(document).ready(function () {
 $('ifram#IframeID').load(function () { //The function below executes once the iframe has finished loading<---true dat, althoug Is coppypasta from I don't know where
     var varStoresNameIframe =$('iframe#IframeID').contents().find('.buttonsClass');
        $(varStoresNameIframe).click (function () {
            $('html , body').animate({ scrollTop: 0 }, 'slow'); 
        }); 
   });
});

Related link:

  • jQuery’s document ready() event and iframe

So the masterkey for me was the line:

$('ifram#IframeID').load(function () {