Friday, December 16, 2011

How to set the correct DOCTYPE

By default Domino prints out the following, half decent DOCTYPE, leaving out the link to the DTD:

<!DOCTYPE HTML PUBLIC 
   "-//W3C//DTD HTML 4.01 Transitional//EN">

This causes browsers to render the page in quirks mode and not care very much about standards. This makes it harder to get pages to render the same in the different browsers (Internet Explorer, Firefox, Chrome).

If you care about a correct layout of the page you would want something like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"> 

Or if you're lazy, like I am, and maybe want to pretend to do HTML 5, use:

<!DOCTYPE html>

For Xpages it's simply a setting in the Application Properties, Xpages tab:



For a LotusScript agent as straightforward as printing the content-type, a blank line and then the doctype.

Print "Content-type: text/html"
Print
Print "<!DOCTYPE html>"
Print "<html>"
...

For forms (and views that are captured in a $$ViewTemplate form) it's a bit harder, unless you know how to do it:
  1. Create a computed for display field named "$$HTMLFrontMatter"
  2. Hide it
  3. Set its value to"<!DOCTYPE html>" (or whatever doctype you prefer)
Et voilĂ ! That's it. Happy little doctypes, causing browsers to render the pages in standards compliant mode.

Happy hacking!

2 comments:

  1. Great stuff! Was breaking my head for couple to get out of quirks mode.

    ReplyDelete