Tuesday, June 3, 2008

HTML 4.01 and XHTML 1.1

Finally converted the index page of my site to XHTML 1.1 and HTML 4.01, depending on what browser the page viewer is browsing from. Since the index is in PHP, I can manipulate the headers so it will display HTML 4.01 on Internet Explorer users or XHTML 1.1 (default) for viewers who use Mozilla Firefox (v2 or later) or any browser that supports XHTML. All stylesheets used are CSS3 validated.

Since there are google ads on my pages, I decided to revert the mime types to text/html instead of application/xhtml+xml since most if not all of the javascript ads like adsense does not support xhtml yet. There are a lot of sample PHP code to do this and after gathering enough examples I have created my own. Here is what my script provides:

  1. If XHTML is supported, send XHTML (with XML) headers to the page but retain text/html as the mime type, and make sure the XML tag is placed on the first line and column of the page.
  2. If XHTML is forced to be the markup language, use application/xhtml+xml as mime type, thereby disabling ads that don't support XHTML and browsers with no support for this mime type will not be able to display the page properly, i.e. some of the page styles are lost.
  3. If XHTML is not supported, HTML 4.01 will be used for the headers with text/html as mime type plus all closing tags "/>" are converted to ">".
  4. If HTML is forced to be the markup language, all HTML 4.01 conditions (see no. 3) will be enabled.
  5. If validation from W3C, the default markup language (XHTML 1.1) and mime type (application/xhtml+xml) is used.
You can validate the markup of your pages at the W3C Markup Validation Service. You can validate your stylesheets at the W3C CSS Validator.

No comments: