在Cordova 3.0中是否有办法检查这是第一次运行应用程序而不使用数据库进行此目的。
答案 0 :(得分:10)
您可以使用localStorage检查变量。尝试这样的事情:
在docummentready事件中:
if(window.localStorage.getItem('has_run') == '') {
//do some stuff if has not loaded before
window.localStorage.setItem('has_run', 'true');
}
答案 1 :(得分:1)
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");
}
答案 2 :(得分:-1)
您必须使用sessionStorage而不是localStorage。
正确的代码是:
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");
}
这是因为localStorage是持久的,而sessionStorage是因为..