Skip to content

Instantly share code, notes, and snippets.

@jrmlstf
Last active December 17, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrmlstf/5652759 to your computer and use it in GitHub Desktop.
Save jrmlstf/5652759 to your computer and use it in GitHub Desktop.
Init app ondeviceready or load if it's a phonegap app or not. From https://github.com/triceam/PhoneGap-Legends/blob/master/js/index.js
//detect if web or phonegap ( via http://stackoverflow.com/questions/8068052/phonegap-detect-if-running-on-desktop-browser)
function isPhoneGap() {
return ((cordova || PhoneGap || phonegap)
&& /^file:\/{3}[^\/]/i.test(window.location.href)
&& /ios|iphone|ipod|ipad|android/i.test(navigator.userAgent)) ||
window.tinyHippos; //this is to cover phonegap emulator
}
function init(event) {
console.log("init app");
}
if ( isPhoneGap() ) {
document.addEventListener( "deviceready", init );
} else {
window.addEventListener( "load", init );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment