我可以在Cordova 2.5上多次听到deviceready吗?

我可以在Cordova 2.5上多次听到deviceready吗?

问题描述:

我可以为每个html网页注册deviceready事件吗?我使用Cordova 2.5的初始化代码,它工作正常。当我把这些代码复制到一个新的html文件,它总是调用index.html的initialize()函数。

Could I register 'deviceready' event for each html page? I use the initialize codes of Cordova 2.5 and it work fine. When I copy these codes to a new html file, It always call to the initialize() function of the index.html.

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        console.log('Received Event: XXX ' + id);

    }
};

===============
HTML档案:

=============== HTML file:

....

 <script type="text/javascript">
                app.initialize();
                </script>

....

设备就绪只会触发一次。它将下一次火灾时,只有当应用程序被杀死,并再次打开。

Device ready will fire only once. It will fire next time only when the app is killed and opened again.