javascript - Phonegap deviceNotReady event? -


like others, i'm trying tell difference between javascript code running in mobile browser , in phonegap webuiview. standard solution wait deviceready event fire, because after fires, know you're in phonegap. how long wait?

i have code want run possible because don't want users sit around waiting. don't want run before phonegap initialized, if it's going initialize. i'm looking devicenotready event fires when after cordova.js code has run , determined there's nothing attach to. or variable can poll tell difference between cordova still loading , cordova having given trying load. there difference?

i hate solution, it's best i've come with. please tell me there's better this:

function whenloaded(callback,timeout) {     var when_loaded_needs_running = true;     document.addeventlistener('deviceready', function() {         if( when_loaded_needs_running ) {             when_loaded_needs_running = false;             callback();         } else {             console.log("deviceready fired late. whenloaded ran.");         }     });     window.settimeout(function() {         if( when_loaded_needs_running ) {             when_loaded_needs_running = false;             console.log("deviceready didn't fire after "+timeout+"ms. running whenloaded anyway.");             callback();         }     }, timeout); } 

a simpler test see if cordova javascript global available - no waiting on event, can execute (as long executes after theoretical <script> include of cordova.js). depending on version of phonegap running, may need test 1 of several global variables.

should simple as:

if(cordova || cordova || phonegap) {   alert('hey im in phonegap webview!'); } else {   alert('regular old browser, aw shucks'); } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -