How catch iframe resize event from inside the ifra

2019-02-22 03:47发布

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.)

3条回答
Ridiculous、
3楼-- · 2019-02-22 04:07

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

$('iframe').resize(function() {} );
查看更多
走好不送
4楼-- · 2019-02-22 04:09
$(body).resize(function(){
    alert('on inside iframe');
});

Edit :

in html

<body onresize="myFunction()">
查看更多
登录 后发表回答