Reputation: 315
I am working on one iPhone app using phonegap. When the user opens the app and goes to the main page, I want to call one function to sync app Database with the Live one. This function should get called only once. i.e. even if the user clicks again on the main page, that function should not get called as it is already called.
I want to call this function under onDeviceReady() function.
function onDeviceReady()
{
if(test.called) {
return false;
}else{
test();
}
}
function test(){
test.called = true;}
I used the above concept but the function gets called again when I click on different page and then if I click on the Main page. i.e because it refreshes the page sets value as false.
What event I should use to call the function only once when the app?
Upvotes: 0
Views: 96
Reputation: 13997
I suggest you make use of the sessionStorage:
function onDeviceReady()
{
if(sessionStorage.getItem("isSync") === "true") {
return false;
}else{
test();
sessionStorage.setItem("isSync", "true");
}
}
The session storage stores the flag as long as the browser is open, so as long as your PhoneGap application is open.
Upvotes: 1