0

This is my local storage, I want to somehow export it from this page and import it to another. How can this be done? I wish to export it for backup purpose too.

enter image description here

halfer
  • 19,471
  • 17
  • 87
  • 173
user2828442
  • 2,213
  • 5
  • 50
  • 87
  • Are both of the projects on the same domain? – BenM Sep 09 '17 at 08:30
  • yes same app, you can think of export and import option – user2828442 Sep 09 '17 at 08:40
  • https://stackoverflow.com/questions/4177803/can-html5-databases-and-localstorage-be-shared-across-subdomains – BenM Sep 09 '17 at 08:41
  • but how can i export it as some file and import it later...in 1 software i saw this option, they used to export it as filename.anyextensionname and later import it – user2828442 Sep 09 '17 at 08:41
  • Probably they just saved the localStorage data in a JSON format, and then wrote an exporter / importer. – BenM Sep 09 '17 at 08:42
  • Possible duplicate of [export Data in localStorage for later re-import](https://stackoverflow.com/questions/13335967/export-data-in-localstorage-for-later-re-import) – yuriy636 Sep 09 '17 at 08:43
  • Also [How to write localStorage data to a text file in Chrome](https://stackoverflow.com/questions/8693289/how-to-write-localstorage-data-to-a-text-file-in-chrome) – yuriy636 Sep 09 '17 at 08:48

1 Answers1

1

To export:

 const export = JSON.stringify(localStorage);

To import:

 Object.assign(localStorage,JSON.parse(import));

How to get the exported string from the one page to the other is another question...

Jonas Wilms
  • 120,546
  • 16
  • 121
  • 140