javascript - 将用户重定向到设备恢复上的某个 URL

标签 javascript cordova ember.js cordova-ios

我正在使用 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/

相关文章:

javascript - AngularJS,<选择>。 <option> 上的 `ng-click` 不起作用

ASP.Net 中的 JavaScript

android - 从状态栏隐藏下载指示器

ember.js - Ember 从 Controller 中的操作更改查询参数

javascript - 从数值创建日期时忽略时区

javascript - 在E4X中过滤2个不同的节点?

ios - 我们可以在 cordova 中识别 UIGesture(在 cordova 中显示 native 侧边菜单的 native 手势)

javascript - Cordova iOS 应用程序,从后台模式返回后出现页面性能问题

ember.js - emberjs 绑定(bind)数据属性

单击浏览器后退按钮时 Ember.js 执行操作