Does localStorage work on local files or it needs to be on a website or server? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Does localStorage work on local files or it needs to be on a website or server?

2nd Apr 2020, 8:01 PM
Redacted
Redacted - avatar
2 Answers
+ 3
Yes, the Storage api (both localStorage and sessionStorage instances) works in offline mode or web file source (localhost or local filesystem)... The only context where there are not working (as cookies) that I know is in android webview (for example if your run web code in the app code playground) but it's working fine in android browsers (through the web code playground)... Maybe iOS app have such limitation too? However, Session api is not a way to access the local filesystem as explained by Martin Taylor (but I guess that's not the subject of the question ^^)
2nd Apr 2020, 9:56 PM
visph
visph - avatar
+ 2
Localstorage does not use to store data in local files,localstorage is a kind of web storage that allows JavaScript sites and apps to store and access data right in the browser with no expiration date.his means the data stored in the browser will persist even after the browser window has been closed. It uses key/value pairs to store the data. there is also a sessionstorage that is used to store data the same as localstorage but sessionstorage is used when you want to stores data for one session (data is lost when the browser tab is closed).
3rd Apr 2020, 6:07 AM
Ishan Shah
Ishan Shah - avatar