onDeviceReady not firing in PhoneGap hello world app

后端 未结 4 2029
梦如初夏
梦如初夏 2020-11-30 16:05

I\'m trying to do a simple alert(\'test\') app, but the event isn\'t being fired, this is the code:

function onLoad() {
    document.addEventListener("de         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 16:31

    This works in Cordova apps (tested on iOS and Android) and ordinary web pages. No library (jQuery) needed.

    // Use onDeviceReady if we run in Cordova
    window.addEventListener('load', function(){
        if (window.Cordova) {
            document.addEventListener('DeviceReady', bootstrap, false);
        } else {
            bootstrap();
        }
    }, false);
    

    The Cordova documentation says that the DeviceReady event is made so, that it can't be missed. The handler will be called even if the device was ready before.

提交回复
热议问题