PDA

View Full Version : sencha cordova native app & html app - what JS code can differentiate between the 2?



gkatz
10 Sep 2013, 5:36 AM
hi all;
I have a sencha html 5 app
sometimes my app runs as a pure html 5 app via web browser and sometimes it runs compiled with cordova as a native app.
I want my JS code (which si the exact same code in both permutations) to be able to differentiate between the 2 modes. what's the best practice for this? I am looking for something like:
(is app native) ? get some resource : get other resource

thanks in advance.

fmoseley
18 Sep 2013, 11:56 PM
I would check Ext.browser.is
http://docs.sencha.com/touch/2.2.1/#!/guide/environment_package-section-browser

Kurt001
23 Sep 2013, 2:38 AM
I think a good starting point is root/touch/src/device.
Take a look at camera, which includes either cordova or a simulator fallback.
You can use the same structure for your problem.

Or you can go with the simple

var browserEnv = Ext.browser.is;
if (browserEnv.WebView && browserEnv.Cordova) {
// Cordova stuff
} else {
// browser stuff
}

gkatz
23 Sep 2013, 4:44 AM
thanks guys!
I will try that