How to reload a page in a Cordova project?

I am building an application using a polymer starter kit and cordova to wrap a project. Now, since I use firebase as a database for storing data, I ended up using two built-in javascript firebase functions to search for user data:

getAuth ()

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.")
  }
});

These two functions require a reboot to return data from firebase, but:

window.location.reload();

does not work

Alos was looking for a Cordoba plugin: webview-reloader , installed it, but redirection and rebooting still do not work.

When I use the reload () function, the screen of my Android phone will be white and the application will stop working. You must close the application and open it again.

enter image description here

+4
2

Cordova :

window.location.reload(true);

, .

+11

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;
}
+3

Source: https://habr.com/ru/post/1609769/


All Articles