Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How catch iframe resize event from inside the iframe (iframe and the page - same domain)

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

like image 582
Ben Avatar asked Feb 28 '12 14:02

Ben


People also ask

How do I resize iframe dynamically based on content?

Answer: Use the contentWindow Property You can use the JavaScript contentWindow property to make an iFrame automatically adjust its height according to the contents inside it, so that no vertical scrollbar will appear.

How do I resize an iframe?

Edit the width attribute. You should see the attribute "width=" after the URL in the iframe tag. Edit the width in pixels in quotations (" ") after the "width=" attribute. For example, if you want the width to be 300 pixels, you would enter "width="300px"" after the URL in the tag.


2 Answers

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

Edit :

in html

<body onresize="myFunction()">
like image 167
Rizwan Mumtaz Avatar answered Oct 26 '22 18:10

Rizwan Mumtaz


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

$('iframe').resize(function() {} );
like image 36
Nick Beranek Avatar answered Oct 26 '22 18:10

Nick Beranek