sessionStorage over localStorage in PhoneGap
Asked Answered
Y

1

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?

Yangyangtze answered 7/9, 2013 at 7:5 Comment(3)
I've always just used localStorage in my PhoneGap applications. What problems are you running into and what are you trying to store exactly?Shortcake
@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?Yangyangtze
It's hard for me to help you unless you post some code so I can get a better idea of what's going onShortcake
S
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
Sheerness answered 18/12, 2013 at 5:1 Comment(2)
@RohanPatil, not a problem! I've added some usage examples for your reference.Sheerness
the question is 3 months old but thanks for your answer this will help someone like me...Yangyangtze

© 2022 - 2024 — McMap. All rights reserved.