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

2019-01-27 16:00发布

This question already has an answer here:

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.

2条回答
淡お忘
2楼-- · 2019-01-27 16:44

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:

So the masterkey for me was the line:

$('ifram#IframeID').load(function () {
查看更多
登录 后发表回答