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

2024-03-10

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

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 文件:

....

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

....


设备就绪只会触发一次。仅当应用程序被终止并再次打开时,它才会在下次触发。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我可以在 Cordova 2.5 上多次监听 deviceready 吗? 的相关文章