+ 1
Does localStorage work on local files or it needs to be on a website or server?
3 Antworten
+ 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 ^^)
+ 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).