Brandon Werner

iPhone Bug: Websites that serve xhtml breaks Safari

I am a stickler for web standards, and make a lot of effort to ensure this website stays XHTML 1.1 compliant, along with the JavaScript and other code that runs in it (often having to modify plug-in’s code out of recognition). However, until recently I conceded that because Microsoft decided in Internet Explorer 7 not to include an XML parser like every other modern web browser manages to do, I could not serve content as application/xhtml+xml as you should, but instead as text/html.

Being a mentally ill obsessive compulsive designer, it bothered me. Then I stumbled upon this plug-in for Wordpress from Joost de Valk that does the simple PHP code to see if the HTTP_ACCEPT of the browser can take application/xhtml+xml and serves it as such if it can. Otherwise, those with less-than-great browsers get text/html.

Imagine my surprise when, after having made this change and verified that it works on IE7 / Firefox / Safari that when I tried to load my website on Safari Mobile it would load the page but before showing any content promptly crash.

Keep in mind that Apple implies that if your site works on Safari 3.x Beta on either Mac or PC, it will work on SafariMobile as it shares much of the same code base before it forked in October. I am not sure if it’s something about the XHTML 1.1 that I’m using, or any modified Prototype.js or other JavaScript that I’m running while using XHTML 1.1 (using application/xhtml+xml changes how JavaScript code works when interacting with a DOM). However, I’ll repeat that it all parses and renders correctly in xhtml+xml on Safari 3.x and even Safari 2.x.

The bigger problem is that the browser in the iPhone obviously states that it can, in fact, take application/xhtml+xml as a content_type or else the code in the plug-in above would default to text/html. So, if you want your web application to work on the iPhone, best to keep it text/html for now.

One Response to “iPhone Bug: Websites that serve xhtml breaks Safari”

  1. ben Says:

    erm.. Apple could still be right, remember:
    - prototype-ing alters javascript at at a fundamenal-level
    - DOM implementations for mobile browsers are (usually) reduced

    Does this require a quick retest with the js (or at least prototype) commented out..?

Leave a Reply