I read that the only way to get my php/js web app not to reset each time the visitor click on icon is to put the cookies in localstorage. I did read Trouble Using LocalStorage to Store Cookie in Mobile Web App who had the same issue but there is no clear solution or at least i don't manage to make it work. I can't figure out how to do something operational from there. Has anyone implemented someting that he could show the code for. Thanks
1 Answers
If by reset you mean go to the start page (or more precisely the page in which the user choose to download the app), this can be achieved in several ways, cookies and localStorage are two nice and simple ways. Since I'm already storing loads of data in localStorage in my guestlist web app, i choose to use cookies for this. Here's how I did it:
(N.B. I'm using the jquery cookie plugin so if you're about to copy paste this code, make sure to implement the plugin first. Let's get down to business)
In each seperat page, set/overwrite the cookie "userLocaltion" with the "current location":
$.cookie("userLocation", "addGuest", { expires: 1 }); //persists for 1 day
Similarly, call the function userPreviousLocaltion() at the top of each page and create the function using switch case (shown below). Since most of my subpages lie within my index.html, I'm triggering a click on a button rather than sending the user to separate pages:
function userPreviousLocaltion() {
var userLocation = $.cookie("userLocation");
switch (userLocation) {
case "addGuest":
$('#addGuestFooterWrap').trigger('click');
break;
case "stats":
$('#statsFooterWrap').trigger('click');
break;
case "utilities":
$('#settingsFooterWrap').trigger('click');
break;
case "bookings":
$('#bookingsFooterWrap').trigger('click');
break;
case "guestlist":
window.location = "guestlist.html";
break;
default:
console.log("do nothing, stay on first page.");
}
}
Hope that helped!

- 2,953
- 3
- 26
- 37