Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect iframe resize?

Is there a way to detect if content of my iframe has changed?

My workaround is I have a loop which constantly check for the height of the content it effective but not efficient is there another way of doing this?

like image 856
yoshi Avatar asked Aug 17 '09 08:08

yoshi


2 Answers

Since the contents of the iframe has a separate window element, you can do this in a script inside of the iframe.

$(window).resize(function(){
  var object = $(this)
  // Use `object.height()` and `object.width()`.
});

You could also use $("#the_iframe")[0].contentWindow.window (or something like that) instead of window to access the window object of the iframe from the scope that contains the iframe.

like image 129
August Lilleaas Avatar answered Sep 20 '22 14:09

August Lilleaas


      setInterval(function() {
                var ifm = document.getElementById("UIMain");
                var h = ifm.contentWindow.document.body.scrollHeight;
                ifm.height = h < 400 ? 400 : h;
          }, 800);

pure javascript is OK.didn't need jquery.

like image 26
SleeplessKnight Avatar answered Sep 19 '22 14:09

SleeplessKnight