onDeviceReady not firing in PhoneGap hello world app

后端 未结 4 2008
梦如初夏
梦如初夏 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:20

    I would rather take an asynchronous approach, like so:

    bindEvents: function () {
        var me = this;
    
        document.addEventListener('deviceready', function () {
            me.onDeviceReady();
        }, false);
    
        $(document).ready(function () {
            me.onDocumentReady();
        });
    },
    
    documentReady: false,
    onDocumentReady: function () {
        this.documentReady = true;
        this.checkReady();
    },
    
    deviceReady: false,
    onDeviceReady: function () {
        this.deviceReady = true;
        this.checkReady();
    },
    
    checkReady: function (id) {
        if (this.documentReady && this.deviceReady) this.load();
    },
    
    load: function () {
        // do stuff
    }
    

    This way you don't risk attaching handlers after the event has occurred.

提交回复
热议问题