How catch iframe resize event from inside the ifra

2019-02-22 03:20发布

问题:

I try to listen from inside of iframe to changes of iframe width/height with:

$(window).resize(function(){
    alert('1 on inside iframe');
});

or:

$(window.parent).find('iframe').resize(function(){
    alert('2 on inside iframe');
}); 

but nothing happens when iframe size changes. (I need a cross-browser solution: IE7, Chrome, Firefox, Safari.)

回答1:

$(body).resize(function(){
    alert('on inside iframe');
});

Edit :

in html

<body onresize="myFunction()">


回答2:

You need to call the resize() handler from the parent document on the iframe:

$('iframe').resize(function() {} );


回答3:

Try that : http://www.iframehtml.com/iframe-scripts.html#resizeable-iframe

Or that : http://css-tricks.com/snippets/jquery/fit-iframe-to-content/