Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing iFrames based on its contents' height only working to enlarge?

Take a look at the attached codepen to see what I mean. Try reducing the width of your browser, the frame should correctly resize. Then maximize your browser window and note that the frame doesn't re-adjust its height.

I have multiple frames stacked ontop of each other so this is quite an annoying issue.

I've tried using .height(), .outerHeight(), .innerHeight(), .scrollHeight and .clientHeight to no avail.

https://codepen.io/anon/pen/gxaLPW

var newHeight = $('#frame').contents().height();  
$('#frame').attr('height', newHeight);

Thanks in advance for any/all help!

like image 254
Craig Smith Avatar asked Jan 31 '26 21:01

Craig Smith


1 Answers

try this

function resizeFrame() {
  var newHeight = $('#frame').contents().find("body").height();
  $('#frame').attr('height', newHeight + 20);
}
like image 179
ewwink Avatar answered Feb 02 '26 09:02

ewwink