0

I'm working on an Apache Cordova based project. This project relies on access to certain device features, like access to the device object.

This object will never exist when I'm debugging our application in a browser, because Cordova is not loaded.

When running in a browser, I would like to use certain mocks and dummy values to make debugging easier, but I don't know if the absence of device is due to running in the browser, or due to a problem at runtime.

How can I determine if I'm currently running in a browser, an emulator or an actual device?

Der Hochstapler
  • 19,560
  • 15
  • 87
  • 126
  • possible duplicate of [Detect between a mobile browser or a PhoneGap application](http://stackoverflow.com/questions/10347539/detect-between-a-mobile-browser-or-a-phonegap-application) – Der Hochstapler Aug 12 '14 at 14:59

1 Answers1

0

I would use almost identical index.html for different platforms, in android/ios versions, include cordova.js, capture deviceready etc. while on web/browser version, I would only load my own js. You can set a platform variable in each. I suppose you get the idea. This way, you wouldn't rely on cordova and affected with possible changes to cordova in the future.

As things get complicated, you might want to check an mvvm js framework such as angularjs and use dependency injection.

mentat
  • 2,668
  • 1
  • 19
  • 39