Practical eCommerce

Developer’s Diary Blog Home · F.A.Q.'s

HOME · Tuesday, July 8, 2008

Developer’s Diary

Using iFrames in xHTML 1.0 Strict

Just kidding… you can’t. But it’s a good title for a blog post since if you run into the problem that I ran into, you probably searched for that. The reality is that iFrames are a bad idea, and have been for years. The harsher reality is that they are not allowed at all in xHTML 1.0 Strict, meaning that either a browser will not even display it (which is probably the better option) or it is displayed but causes your code to not validate. Usually this never comes up, since we usually just assume that frames are bad and to avoid them.

But what about when you need to upload some images and you want to do it without updating the page? Ajax does not allow for file uploads, so that is not an option. A good example of this is a Wordpress interface when you are creating a new article. In order to allow someone to upload an image for placement in their post, there is an iFrame there to accomodate that. At least in my installation, I wouldn’t be surprised if they have upgraded that part. Either way, I want our editorial staff to be able to upload images when they are composing articles without having to refresh the page (and potentially destroy their edits). An iFrame is not an option since I am taking great care to make sure that this application is XHTML 1.0 strict, and also compliant in the Big Four browsers.

Enter the object element, whose sole purpose is to pull in external things and display them. Think of a flash presentation that is rendered in an object element with the help of a plugin. Quicktime movies displayed on a webpage use an object element and also a quicktime plugin. It turns out that you can use the object element as an iFrame, which will be xHTML 1.0 compliant and also (in my opinion) much more versatile and reliable than an iFrame. Let’s be clear, it’s not perfect, but it’s a good option to the iframe. I could also see some interesting “widgets” being developed that take advantage of this behavior.

Actually, to catch myself in a lie real quick, I didn’t test this yet in IE6. That’s partially because I haven’t gotten around to it but also because I just don’t care. As time goes on it will be going away, and it’s important to look to the future when developing and application, and not to the past (too much). So really I can only confidently say that this works in IE7, Firefox, and Safari. There, I said it.

So here is the code. For the most part, it’s just like using an iFrame except that the tag is different. Otherwise nearly all the behaviors are the same as an iFrame with the additional bonus of being able to style it a but more in all browsers. Not to mention that it validates. Simply place this code in your HTML document where you would normally place your iFrame:

And that is it. As you can see, the data attribute replaces the iFrame’s src attribute. Since in this case I am only loading html pages into the object, I specify that the type is text/html. The only thing to note is that your browser will probably try to cache the “frame”, or the content that was loaded into the object. This can cause some problems depending on your application, and at the very least is annoying during development. In order to suppress this behavior I send the following headers with the page that is loaded into the object (/path/to/html_file.php):

Expires=0
Pragma=no-cache
Cache-Control=no-cache, no-store, must-revalidate

I suppose in this example you would do this with PHP before the output of the /path/to/html_file.php is sent to the browser. In my case I am working with Rails, so I specify these headers in the controller for this page. Basically the same thing. You’ll have to figure that one out for your application, but if that solves a headache with trying to figure out why changes are reflected during development.

And that is my little find on object elements. While I can’t stress enough that this isn’t much better than frames, and should always be a last resort, it does work. And it works well across different browsers. Search engines will not follow through, like frames, so this should not be used on public pages or pages where you want good SEO form. I’m using it in a protected administration area that the search bots won’t have access to. And that is my disclaimer. Otherwise, have fun.

↑ Back to Top

Comments:


Leave a Comment:

Brian Getting

Brian Getting is the Online Director at Practical eCommerce, specializing in website design and application development.

Calendar

July 2008
S M T W T F S
« May    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

Browse blog posts by category.

RSS Content Feeds

Technorati Tags

Ecommerce Articles

Browse All Articles
Browse our complete archive of ecommerce articles.
Accounting, Management & Legal
Ecommerce articles related to managing a small business including ecommerce accounting, business strategy and legal considerations.
Conversion & Usability
Online business articles about converting web site visitors into customers and how to gauge and improve your business website's usability.
Development & Programming
Articles to help designers, developers and programmers create successful, search engine friendly ecommerce websites and improve existing ones.
Hosting, Infrastructure & Software
Articles for ecommerce businesses about ecommerce web hosting, business infrastructure, business strategy and helpful ecommerce & small business software.
Interviews & Profiles
Interviews with prominent ecommerce business personalities and profiles of successful online businesses.
Inventory & Shipping
Ecommerce articles about inventory management, ecommerce order fulfillment and product shipping considerations.
Marketing & Revenue Growth
Articles relating to online marketing, email marketing and using the Internet to growing your business.
Search Engine Optimization
Search engine optimization articles for ecommerce business owners, strategists, marketers and developers.
Shopping Carts & Online Payments
Articles covering ecommerce shopping cart platforms and options for choosing an online payment gateway.
Training & Education
Tutorials and articles providing training and education for ecommerce business owners and developers of ecommerce websites.

Search Articles

Ecommerce Community

Ecommerce Blogs
Read our blogs about ecommerce topics written by industry professionals.
Community Forum
Connect with other ecommerce professionals to trade advice and answers in our community forum.
Podcasts
Check out our ecommerce podcasts covering topics ranging from interviews to tutorials.
RSS Content Feeds
Subscribe to our RSS feeds and have fresh ecommerce content delivered to you.

Ecommerce Resources

Free Email Newsletter
Sign up for Ecommerce Notes, our free email newsletter for ecommerce business owners and developers.
Ecommerce Directory
Browse our directory of ecommerce products and services, or submit your own listing in our directory.
Ecommerce Glossary
Familiarize yourself with terminology or submit terms to help others with our Ecommerce Glossary.
Events Calendar
Find out about upcoming ecommerce events or invite other ecommerce professionals by posting your own event.
Press Releases
Browse ecommerce related press releases and post your own press release for distribution.
Ecommerce Store & Back Issues
Pick up back issues of Practical eCommerce magazine along with other merchandise from Practical Ecommerce

About Practical eCommerce

Frequently Asked Questions
Look at frequently asked questions regarded using our website, subscribing to our magazine and more.
Advertising Information
Information about advertising in Practical eCommerce magazine, on our website, or in our email newsletters.
Editorial Sharing
Learn about options for sharing our content with your visitors, customers or employees.
About Us
Learn more about Practical Ecommerce magazine and meet our staff.
Contact Us
Contact Practical Ecommerce at any time for more information. We'd love to hear from you.
Advertisement Stone Edge TechnologiesArial Software

Copyright 2007 Confluence Distribution, Inc. and Practical eCommerce.
All Rights Reserved.

Privacy PolicyConditions of UseContact Us