Thursday, 23 August 2007

if (window.opera && opera.wiiremote)

While my current readership maybe small (4 at last count) it is diverse. As such I'm sorry that some posts maybe of absolutely no interest to some. For example, today's post is probably relevant to only 1 of my readers!

Object detection is considered the best way of implementing cross browser JavaScript -- that is check to see which methods are available and then use the correct combination to achieve whatever it is you are trying to do.

Detecting the Opera web browser is easy as it's the only browser to implement the window.opera object. The Nintendo Wii console has an Opera web browser but until yesterday I had no idea how to recognise it as different to the PC version of Opera without looking at the user agent string, which can be easily spoofed.

It turns out, however, that Opera on the Wii has extra objects that allow access to details of the Wiimotes -- opera.wiiremote. So we can use this to detect when we are running JavaScript on the Wii by checking for window.opera && opera.wiiremote.

Of course we can do much more than just detect that we are running on the Wii. As far as I can tell the only thing that can't be detected are the values from the accelerometers. There are a number of demo pages as well as a simple game called Wii Roll that you can try.

Of course you can't develop web pages on the Wii so testing web pages will mean trekking backwards and forwards between your PC and the Wii. Of course someone else has already thought of this and developed a wiiremote emulator script so that you can develop and test on your PC.

Post a Comment