如何在 Cordova 项目上重新加载页面?

新手上路,请多包涵

我正在构建一个应用程序,使用 聚合物入门套件科尔多瓦 来包装项目。现在,由于我使用 firebase 作为存储数据的数据库,我最终使用了两个本机 firebase javascript 函数来查找用户数据:

获取授权()

 var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
var authData = ref.getAuth();
if (authData) {
  console.log("Authenticated user with uid:", authData.uid);
}

onAuth()

 var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.onAuth(function(authData) {
  if (authData) {
    console.log("Authenticated with uid:", authData.uid);
  } else {
    console.log("Client unauthenticated.")
  }
});

这两个函数需要重新加载才能从 firebase 取回数据,但是:

 window.location.reload();

不起作用

Alos 寻找了一个 Cordova 插件: webview-reloader ,安装了它,但重定向和重新加载仍然无法正常工作。

当我使用 reload() 函数时,我的 Android 手机屏幕变白并且应用程序停止工作。需要关闭应用程序并重新打开。

在此处输入图像描述

原文由 Dragod83 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 430
2 个回答

由于 Cordova 是浏览器窗口的包装器:

 window.location.reload(true);

它适用于浏览器窗口和 Cordova 应用程序。

原文由 ShatrdWing 发布,翻译遵循 CC BY-SA 3.0 许可协议

这适用于 iOS 和 Android(至少适用于 2016 平台版本)。

 // keep startup url (in case your app is an SPA with html5 url routing)
var initialHref = window.location.href;

function restartApplication() {
  // Show splash screen (useful if your app takes time to load)
  navigator.splashscreen.show();
  // Reload original app url (ie your index.html file)
  window.location = initialHref;
}

原文由 Sebastien Lorber 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题