0

so basically what I would like to do is read x-json file on my hdd for example and load it into the localstorage of my browser. So far I went with

const localStorageName = 'events';
this.eventList = JSON.parse(localStorage.getItem(localStorageName)) || {};
localStorage.setItem(localStorageName, JSON.stringify(this.eventList));

to save something into the localstorage as a string.
As far as I can think and Iam pretty new to js, json and coding/programming in general, i would have to "unstringify" if that is even a word, the file when loading it and put it back into js right?
Well if it is even possible to load a local file into localstorage that is.
Iam well aware that localstorage can only read/store strings, so it has to be a json file that must be read/load.
Overwriting the data is not an issue. Security is also not an issue. Why do I want this?
Iam creating a local calendar with an event list/planner but the local cache on the clients are being erased upon shutting down/restarting, so the events are getting erased. And this has to be offline.

So if this is even possbile any help is highly appreciated!
Thank you in advance.

  • 1
    It looks like you've already figured out how to do this. What's the problem? – Robert Harvey Jun 10 '20 at 23:07
  • If you're trying to load a local file, see [Read a local text file using Javascript](https://stackoverflow.com/questions/27522979/read-a-local-text-file-using-javascript) but be wary of bad answers (always check the comments) – Phil Jun 10 '20 at 23:09
  • @Phil hmm yes I see, that might work, thank you for that. – mlkbonez Jun 10 '20 at 23:26
  • @RobertHarvey Iam not sure how :D but i will figure it out, guess I still dont completely understand it myself. – mlkbonez Jun 10 '20 at 23:27

0 Answers0