[FIXED] How to reload page on a Cordova project?

Issue

I am building an app, using polymer starter kit & cordova to wrap the project. Now, since I use firebase as a database for storing data, I ended up using two native firebase javascript function to find 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.")
  }
});

Those two functions require a reload to bring back data from firebase, but :

window.location.reload();

doesn’t work

Alos looked for a Cordova plugin: webview-reloader, installed it but redirect and reload still not working.

When i use the reload() function the screen of my android phone is going white and the application stop working. Need to close the app and open it again.

enter image description here

Solution

Since Cordova is a wrapper around a browser window:

window.location.reload(true);

It works for the browser windows as well as a Cordova app.

Answered By – Hgehlhausen

Answer Checked By – Timothy Miller (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published