So here are 3 ways to detect if your application is running as a Cordova/Phonegap application.
1 – The cordova.js will set the cordova object in the global scope. If it is there then you are most likely running in a Cordova scope.
2 – Cordova will run your application as you would open a HTML document from your Desktop. Instead of the HTTP protocol it will use FILE. Detecting this will give you a chance to assume that your app was loaded locally.
3 – Use the load event of the cordova script to detect the context. The script include can be easily removed in the build process or the script loading will simply fail in a browser. So that this global variable will not be set.