aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Testing for device motion capability Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Testing for device motion capability" Watch "Testing for device motion capability" New topic
Author

Testing for device motion capability

steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
The standard line in every blog, tech article, etc., that I've seen on this goes something like this:


So, first thing I do is open that page in FF on my PC, and, lo and behold, it says we have motion. And, even the MDN docs say that the above code is the correct test.

But, it seems like I'm testing for the existence of the constructor for an event object, not a capability of the device. And, unless the browser is actually going to conditionally define the constructor, it makes sense that it would always be there. I wonder if the test should be something like that below, based on the hope that the interval is a static property gleaned from the actual device. (Unfortunately, my phone doesn't support motion, so I don't have a way to test this.)



If not, then what is a correct test (one that will not report motion capability in FF in a device that doesn't have motion capability)?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
um, isn't that if statement saying you do NOT have it?

Shouldn't it be !==?

Eric
steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
Eric Pascarello wrote:um, isn't that if statement saying you do NOT have it?

Shouldn't it be !==?

Eric


Ummm ... oops, you're right. That's what happens when you try to type beyond your capabilities

The actual code I tested had the !== and reported the object was present. Firebug also lets me see the object. I assume that's so FF can create the event object when running on a capable device.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Testing for device motion capability