gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:11 24 4
gpt4 key购买 nike

我可以为每个 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>

....

最佳答案

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

关于javascript - 我可以在 Cordova 2.5 上多次监听 deviceready 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15629278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com