Phonegap/Cordova 构建 onResume 事件不工作
Phonegap/Cordova build onResume event not working
我正在使用 Phonegap Build 创建一个应用程序,我只是在 webview 中加载整个网页。
问题是,如果我加载网页,onResume 和 onPause 事件不会触发,如果我不加载页面,它就会正常触发。
我用这个
function onBodyLoad() {
document.addEventListener('deviceready', onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("resume", onResume, false);
document.addEventListener("pause", onPause, false);
setTimeout(function () {
//if I don´t use this, then the events are working,
//but as soon as I load the page the events are not firing?
document.location.href = "http://somepage.se/";
}, 0);
}
如果我不加载网页,为什么活动仍然有效?
已解决!我的错误是,当我用 window.load 加载时,它会替换我的空洞页面,因此它永远不会触发该事件,因为它已经消失了。所以我必须使用 jQuery 将其加载到 div 中,然后它将页面加载到现有页面中,而不是替换它。
我试图找出你遇到的问题,我可以告诉你这不是你实际遇到的问题。
onPause
事件在本机平台将应用程序置于后台时触发,通常是 当用户切换 到另一个应用程序时。
OnResume
事件在从后台检索 应用程序时触发。
如需完整文档,请阅读 here!
我正在使用 Phonegap Build 创建一个应用程序,我只是在 webview 中加载整个网页。
问题是,如果我加载网页,onResume 和 onPause 事件不会触发,如果我不加载页面,它就会正常触发。
我用这个
function onBodyLoad() {
document.addEventListener('deviceready', onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("resume", onResume, false);
document.addEventListener("pause", onPause, false);
setTimeout(function () {
//if I don´t use this, then the events are working,
//but as soon as I load the page the events are not firing?
document.location.href = "http://somepage.se/";
}, 0);
}
如果我不加载网页,为什么活动仍然有效?
已解决!我的错误是,当我用 window.load 加载时,它会替换我的空洞页面,因此它永远不会触发该事件,因为它已经消失了。所以我必须使用 jQuery 将其加载到 div 中,然后它将页面加载到现有页面中,而不是替换它。
我试图找出你遇到的问题,我可以告诉你这不是你实际遇到的问题。
onPause
事件在本机平台将应用程序置于后台时触发,通常是 当用户切换 到另一个应用程序时。
OnResume
事件在从后台检索 应用程序时触发。
如需完整文档,请阅读 here!