O'Reilly logo

Firefox Hacks by Nigel McFarlane

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #58. Pick Display Modes for HTML and XML

Firefox has several display options for web content. Here's how to pick between them.

This hack explains how to specify a display contract between a web page and Firefox. A display contract is an agreement between the content author and Firefox that guarantees that the content will be displayed as the author intended, right down to the tiniest detail. That means no more guesswork about browser behavior. This hack applies to all Mozilla-based browsers, including Compuserve Version 8 and later, Netscape Versions 6 and later, the Mozilla Application Suite Versions 1.x, Camino, and so on.

To make a display contract, put hints and standards references in or near the content. Provided the content author puts these in, Firefox will fall into line with absolute predictability. You'll need to add several types of hints.

Tell Firefox What the Content Is

If content is delivered across the Internet, everything depends on the HTTP Content-Type header, which advertises a MIME type for the content document. Firefox always follows the MIME type, no matter what. Here are the correct headers to use for HTML, XML, and XHTML:

Content-Type: text/html
Content-Type: text/xml
Content-Type: application/xhtml+xml

It's the third line that Internet Explorer (IE) can't always understand. To support IE, you have to fudge a separate type for IE at the server [Hack #27] For complex XML cases [Hack #60] and for Firefox-specific XML such as XUL [Hack #68] , use this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required