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

4ioopgfo  于 2022-11-15  发布在  其他
关注(0)|答案(3)|浏览(153)

我正在构建一个应用程序,使用polymer starter kit & cordova来 Package 项目。现在,由于我使用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手机屏幕变白色,应用程序停止工作。需要关闭应用程序并重新打开它。

yqyhoc1h

yqyhoc1h1#

由于Cordova是浏览器窗口的 Package 器:

window.location.reload(true);

它适用于浏览器窗口以及 cordova 应用程序。

eufgjt7s

eufgjt7s2#

这适用于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;
}
q9rjltbz

q9rjltbz3#

if (this.cordovaService) { // is cordova
    this.window.location.href = `${this.window.location.protocol}//${this.window.location.host}`;
} else {
    this.window.location.reload();
}

相关问题