Page 1 of 1

Local Storage Variable Lasts for More than One Session?

Posted: Mon May 27, 2013 5:57 pm
by Ryan Bloom5585665

Hello,

I have two input fields (EquipmentAmount & AccessoryAmout), upon value change a local storage is created (MacPrice & AccPrice). When the user goes to the next page, they have a back button. When they go back, I want the fields that they entered to be filled in with the local storage variable. To accomplish this, I have a set property on the page load to have the input fields read from the local storage variables accordingly.

I have the setting and reading working properly, however, when the user closes the browser and then goes back again, their values are still there. Is there a way to have the variables only last one session?


Local Storage Variable Lasts for More than One Session?

Posted: Mon May 27, 2013 6:41 pm
by Maryna Brodina

Hello!
1) You can add JS on page Load event for start screen to refresh localStorage variables (if you don't use full screen refresh while navigation between screens);
2) You can use sessionStorage instead of localStorage (data refreshes when session is over);
3) If you use full screen refresh option you can refresh localStorage variables manually, but it's a part of your app logic, should be coded by you.


Local Storage Variable Lasts for More than One Session?

Posted: Mon May 27, 2013 7:46 pm
by Ryan Bloom5585665
  1. What would that JS be?
    1. Is sessionStorage built into the app logic?
    2. I don't have a full screen refresh option because the back button is in the header.

Local Storage Variable Lasts for More than One Session?

Posted: Mon May 27, 2013 8:21 pm
by Maryna Brodina

1) On page Load run the following code:
codelocalStorage.setItem('name1', '');
localStorage.setItem('name2', '');
............
localStorage.setItem('nameN', '');/code

where name1, nameN - names of all localStorage variables you need to refresh

2) no, it's not built into the app logic, you also need to use custom JS code (unfortunately don't have any code sample, it should be coded by you)