View Full Version : Dynamically Shrink/Expand iFrame?

07-05-2012, 10:36 PM
Hey hi hello! I've been working a lot with iFrames (or more specifically, an iFrame) on a website I've been designing for a while. I've been using one large iFrame to display all of the content, and every link on the website targets the frame so it can reload without a page refresh. And it looks pretty cool!

...except that I haven't found a good way to dynamically resize the frame to fit the content. I've found many multiple (multiple multiple) scripts to make the frame expand, but I have yet to find one that shrinks it. I've been searching all afternoon for a solution! It's been rather uncool.

Anyway, yeah, do you guys know of a cross-browser fix to this problem? Any help would be wondrous. Thanks so much!

07-05-2012, 11:21 PM
If you are using jQuery, this will do it. In the page that contains the iFrame, place this:

function resizeIframe(frameID,newHeight){

On every page that appears within the iFrame, put this:

$.getDocHeight = function(){
$thisFrameHeight = Math.max(
return $thisFrameHeight;