Dump iframes and use object elements instead
Do you sometimes need to use
iframe elements to inject content into sites you build? I do. Not very often, luckily, but it does happen. Usability and accessibility issues aside, doing so also forces me to use a transitional DOCTYPE, something I’d rather avoid.
There is an option, but it is of little practical use since it doesn’t work in Internet Explorer: the
object element. Or so it was believed. The other day I came across Stuart Colville’s post No more iframes?. In the post, Stuart points to Aleksandar Vacić’s article Insert HTML page into another HTML page, which explains a very clever way of using an
object element to insert an external HTML document into a page.
Aleksandar solved the problem by finding a value for the
classid attribute that makes IE accept an external HTML document as the content of the
object element. And it actually seems to work. Stuart discussed Aleksandar’s technique with a couple of colleagues and cleaned it up slightly code-wise. View Using an object Element instead of an iframe for a demo and explanation.
I haven’t tried this myself yet, but I’m sure I’ll find an opportunity to do so sooner than I’d like to.
Update (January 2010): The demo referred to above does not use conditional comments to hide the
classid attribute from non-IE browsers, which causes the technique to fail in recent versions of Firefox. Using conditional comments as in Aleksandar’s article should fix that.
Subscribe / follow
- Front End Developer at Health Startup at WellnessFX (San Francisco, CA, Ca, US)
- Remote Sensor Software Developer at charity: water (New York, NY, Ne, US)
- Sales Engineer at arvato Systems North America (New York, NY, Toronto, Canada, Ne, US)
- Talented Web Designers & PHP Developers - Let's Talk! at Advant Interactive (Venice, CA, Ca, US)
DreamHost web hosting
Use the promo code 456BEREASTREET3 to save USD 20 when you sign up for DreamHost