How to catch iframe resizing from inside iframe (iframe and page are the same domain)

I am trying to listen to iframe width / height changes from inside an iframe using:

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

or

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

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

+6
source share
3 answers
 $(body).resize(function(){ alert('on inside iframe'); }); 

Edit:

in html

 <body onresize="myFunction()"> 
+2
source

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

 $('iframe').resize(function() {} ); 
+1
source

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


All Articles