function initializePhoneGap( success, failure ) { var timer = window.setInterval( function () { if ( window.device ) { window.clearInterval( timer ); success(); }; }, 100 ); window.setTimeout( function () { //failsafe if ( !window.device ) { //phonegap failed window.clearInterval( timer ); failure(); }; }, 5000 ); //5 seconds }; window.onload = function () { initializePhoneGap( function success() { //start app document.getElementById( 'result' ).textContent = 'phonegap: success'; }, function failure() { //phonegap failed document.getElementById( 'result' ).textContent = 'phonegap: failure'; } ); };
should fail on desktop after 5 seconds <div id="result">phonegap:</div> <script> initializeHeader( 'Phonegap - onDeviceReady() wasn\'t fired', 'http://stackoverflow.com/q/15606870/918414' ); </script>