• Home
Pictures Archives Travel RSS

iFrame dynamic resizing revisited

05 June 2008 | Coding, JavaScript | 8 Comments

Its time to revisit the burning question once again!

“Is there a reliable way to dynamically resize the iFrame height according to its contents?”

Well according to my previous post I thought I nailed it! But I soon found out it wasn’t all that reliable! :( So it wasn’t the silver bullet I was hoping for. 

So as a part of “E2″ development, my mate Rob and I started on a journey to conquer this once and for all! Our findings were some what disturbing!

First of all, there ISN’T a silver bullet that solves the problem for all the browsers. The basic problem is that iFrames (along with applets) are handled differently on browsers as compared to other elements. In fact iframes are not handled by browsers at all, but by the OS. So the solution will never be the same for all the browsers. So heres what we found. 

IE 6/7

The solution is a nasty CSS hack. Until yesterday I have not heard about this trick. The trick is to have an expression like this in your CSS.

.iframe { height: expression(document.documentElement.clientHeight + "px"); }

IE being a special browser, it detects this expression and resize your iFrame accordingly. But there is a down side to this. Having expressions in your CSS affects your site’s performance. But having battered by this issue for days and nights, I am willing to go down this path for now!

FireFox 2 and 3 / Safari 3

Yes, they both behave the same way! So trick here is to wrap your iframe with a DIV tag and assign an  absolute positioning to the DIV. 

<div id="iframe_wrap"><iframe scrolling="auto" id="iframe" name="iframe" class="iframe" frameborder="0" src="source_page.html" width="100%" height="100%"></iframe></div>

And then apply styles to the DIV tag like below. 

#iframe_wrap {
position:absolute;
top: 60px;
left: 0;
right: 0;
bottom: 0;
}

This nice trick will get ride of the “double scrollbar” phenomenon as well. 

So there you go. The job is done!!! (At least for now) Special thanks to Rob for doing most of the “googling”!

Popularity: 80% [?]

« Previous Entry

Next Entry »

Recent Comments

  • Kalpan: Hi I am looking for the
  • Richard Glanvill: If the output generated by
  • Concentratedmedia Blog » Blog Archive » Creating Dynamic iframes for IE 6 & 7, Safari 3, Firefox 2 & 3: [...] this but the best
  • Suneth Mendis: Combining both is a BAD
  • Julks: Hi Suneth, How to put the

Popular Posts

  • Iframe dynamic resizing… SOLVED!
  • iFrame dynamic resizing revisited
  • Offline blog editor
  • "Fun" with Prototype and IE7 and Tables
  • Using jQuery with Prototype - Sweet!!!

About Me

One life, Live it!

My name is Suneth Mendis. I'm a 29 year old Software Engineer. I live in Brisbane Australia and working for a very exciting company called Ephox.

  • Recent Posts

    • Ignorance is your loss
    • Auto coloring of child nodes using Prototype
    • iFrame dynamic resizing revisited
    • Using jQuery with Prototype - Sweet!!!
    • “Fun” with Prototype and IE7 and Tables
    • What serious lack of sleep can do to a developer…
    • iSurprise
    • Offline blog editor
    • What!?
    • Iframe dynamic resizing… SOLVED!
    • more...
  • Categories

    • Agile
    • Blogroll
    • Coding
    • Gadgets
    • Hobbies
    • Ideas
    • JavaScript
    • Life
    • Mac
    • Prototype
    • Travel
    • Work
    • WTF
  • Links

    • Planet Ephox

Copyright © Suneth Mendis 2008 · Designed by Suneth Mendis · Powered by WordPress