Monday, February 13, 2012

JQueryMobile based Pages dont display in Windows Mobile Emulator

Well, my JQuery mobile based pages don't load in the Windows Mobile emulator or on the Windows Mobile devices used by our clients for UAT.

This is not good!!

Turns out that this is a similar issue that we have seen in the Richfaces 3.3 libraries and I am not sure that this is a known defect or not.

Windows Mobile browser doesn't support implicit toString() methods on objects when used in calls to colsole.log(String) and elements do not have an explicit toString() method.

That makes little sense, what do you mean?
Well, let us consider the simple logging statement below:

var myElement = $('myElementId');
console.log("found element [" + myElement + "]");

In just about all browsers this will work fine, but not in Windows Mobile browser (or IE8 strict mode, but that is another story).

The issue is that javascipt will call an implicit "toString() on the variable "myElement" and it is not defined in Windows Mobile browser and the script will stop executing.


Wow, that is pretty fucked up?
Yes it is.


What can I do to stop this?
You can either write you own toString() helper/utility method or use a better logging/debugging framework which wraps and manages these call.

For example:
var myElement = $('myElementId');
Log.info("found element [%s]", myElement);


var Log = {};
Log.info(msg, itemParam) {
// blah blah blah
//
// There are heaps of logging scripts on the net for you to use
// remember "Unless you need a wheel that isn't round
//                    then one has already been invented"
}



I hope this saves you some pain.

No comments: