There was a W3C recommendation back in 2009 for the Compass API, which included the fieldStrength attribute, a perfect fit for what you are doing.
Unfortunately, it doesn't look like fieldStrength was exposed in any version of phonegap I can find. It doesn't look like CocoonJS implemented any compass features at all.
Apparently, not all devices that offer compass data use a magnetometer either. However, all iPads, and all iPhones since the 3GS, do have true magnetometers. Many android devices have them, but some don't.
Here are links to the low-level API documentation for magnetometer data on android and iOS:
http://developer.android.com/guide/topi ... rs-pos-mag
https://developer.apple.com/library/ios ... index.html