Reputation: 11247
Is there a way in Cordova 3.0 to check if that's the first time the application runs without using the DB for that purpose.
Upvotes: 7
Views: 4401
Reputation: 481
You must use sessionStorage instead of localStorage.
The correct code will be:
var count = window.sessionStorage.getItem('hasRun');
if (count) {
console.log("second time app launch");
} else {
// set variable in localstore
window.sessionStorage.setItem('hasRun', 1);
console.log("first time app launch");
}
It's because localStorage is persistent while sessionStorage ain't..
Upvotes: -2
Reputation: 6029
You could use localStorage to check for a variable. Try something like this:
in docummentready event:
if(window.localStorage.getItem('has_run') == '') {
//do some stuff if has not loaded before
window.localStorage.setItem('has_run', 'true');
}
Upvotes: 10
Reputation: 4748
Dawson Loudon's solution didn't work for me but try this:
var count = window.localStorage.getItem('hasRun');
if(count){
console.log("second time app launch");
}else{
// set variable in localstore
window.localStorage.setItem('hasRun',1);
console.log("first time app launch");
}
Upvotes: 1