Post Format

JavaScript Incompatibilities in Webapps

Below, I present some stumbling blocks that I met during developing a mobile, cross-platform, JavaScript-based WebApp.

Loading and Saving Dates

Virtually all modern browsers are implementing “local storage”, a service to store data locally on the device. The localStorage object implements a so-called key-value store. That works cross-platform amazingly well.

We want to store a date, so we need to transform the date into a string first. To read it back, we need to convert the string to a date object back again. Because JavaScript has a date object since the last century, you expect that it to provides the appropriate functions.

Surprisingly, the standard methods such as date.parse() are not very helpful. The only defined date format is RFC2822, but this format is optimized for English-language people. A date in this format will look like this:

“Mon, 31 Dec 1995 12:30:00”

A much better format is defined in ISO 8601. Dates will look like this: “YYYY-MM-DDThh:mmTZD“.

The complexity is much lower. No month names or week day names must be parsed, and the fields are in a fixed position. So it is much easier to read and write for computers.

Nevertheless, a call to date.parse() with an ISO date does not work in many devices: in my tests, I got errors on devices with Android 2.1 and 2.3, as well as with a BlackBerry OS6 device. The reverse method Date.toISOString() is also missing. ISO-dates are officially supported only since JavaScript 1.8.5 or ECMAScript version 5.

Dialogs and the prompt-method

JavaScript offers built-in functions for simple dialogs:

  • alert()
  • confirm()
  • prompt()

The dialogs of this methods are presented in the correct platform-specific design automatically. Since there are modal dialogs, the application logic becomes trivial. If we want to ask the user for a string, this simple program line is enough:

username = prompt(‘Your username’);

However, Microsoft decided that the prompt-method is a security problem. Because of this, prompt() is no longer supported in Internet Explorer starting with version 7 (in the default setting), and also not in Windows Mobile.

Annoying is that the Windows Mobile browser suppresses the dialog “secretly”. We can not distinguish the result of the suppressed prompt()-call from an empty user input, and so we can no longer react and offer alternatives for text input. So we need to do the unpopular “browser sniffing” again.

Author: Karsten Meier

Weil ich gerne Probleme löse bin ich Informatiker geworden. Ich berate und Konzeptionieren und entwickle mit fast allem, was einen Prozessor hat.

Leave a Reply