11

I am currently developing a PhoneGap application and am using sessionStorage rather than localStorage because we are facing some problems with localStorage.

Are there any downsides to using sessionStorage over localStorage?

Andrew Lively
  • 2,145
  • 2
  • 20
  • 27
Rohan Patil
  • 1,865
  • 1
  • 23
  • 36
  • I've always just used localStorage in my PhoneGap applications. What problems are you running into and what are you trying to store exactly? – Andrew Lively Sep 07 '13 at 14:23
  • @AndrewLively we are storing 1 value in index.html file and using that in main.html after redirecting, by localstorage but in windows mobile app localstorage is not working on redirect so using session for that any solution on this? – Rohan Patil Sep 08 '13 at 06:18
  • It's hard for me to help you unless you post some code so I can get a better idea of what's going on – Andrew Lively Sep 08 '13 at 14:06

1 Answers1

19

sessionStorage gets erased every time you close the application. Other than that there is no difference.

Here is the usage example:

var keyName = window.sessionStorage.key(0); //Get key name
window.sessionStorage.setItem("key", "value"); //Set item
var value = window.sessionStorage.getItem("key");// Get item
window.sessionStorage.removeItem("key"); //Remove Item 
window.sessionStorage.clear();//Clear storage
Allan Spreys
  • 5,287
  • 5
  • 39
  • 44