我正在使用 ember 构建 cordova 应用程序。
在应用程序恢复事件中,我想将用户重定向到路径“/#/location”,在其中检查用户的位置并更新纬度经度。
代码是-
document.addEventListener("resume", onResume, false);
function onResume () {
setTimeout(function () {
window.location.href = '/#/location';
}, 100)
}
但它没有重定向到“/#/location”。
有人可以对此提出建议吗?我做错了什么或者我怎样才能实现这个目标?
最佳答案
在 deviceready
事件之后监听此事件!
The
deviceready
event fires when Cordova is fully loaded. This event is essential to any application. It signals that Cordova's device APIs have loaded and are ready to access.
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
document.addEventListener("menubutton", onMenuKeyDown, false);
}
function onPause() {
// Handle the pause event
}
function onResume() {
// Handle the resume event
}
function onMenuKeyDown() {
// Handle the menubutton event
}
<!DOCTYPE html>
<html>
<head>
<title>Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="example.js"></script>
</head>
<body onload="onLoad()">
</body>
</html>
关于javascript - 将用户重定向到设备恢复上的某个 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43489933/