Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    47
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Dynamically Shrink/Expand iFrame?

    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!

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    If you are using jQuery, this will do it. In the page that contains the iFrame, place this:

    Code:
    function resizeIframe(frameID,newHeight){
      $('#'+frameID).height(newHeight);
      }
    On every page that appears within the iFrame, put this:
    Code:
    $.getDocHeight = function(){
      $thisFrameHeight = Math.max(
            $(document).height(),
            $(window).height(),
            document.documentElement.clientHeight);
       return $thisFrameHeight;
    }
    
    setTimeout("parent.resizeIframe('frameid',$.getDocHeight())",50);
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •