Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 5 local storage

Tags:

html

Can I save data to to either CSV or XML files on offline on client-side via HTML5?

like image 371
Wdos Avatar asked Sep 02 '10 06:09

Wdos


3 Answers

The offline storage is an internal storage. It is not meant to export some files to a specific format / specific folder on disk.

like image 159
Alex Avatar answered Sep 21 '22 01:09

Alex


The web storage API stores data as [key,value] pair where both key,value are Strings.

So data in any format needs to adhere to this mechanism for local storage. So for example, if you have a JSON object like :

{
  name:'John',
  gender:'male'
}

You can store it (through JavaScript) after passing it as a string like :

localStorage.setItem("myObj","{name:'John',gender:'male'}");

For JSON objects, use JSON.stringify() to convert them to strings and use JSON.parse() to read them back.

like image 23
Rajat Avatar answered Sep 20 '22 01:09

Rajat


You can use localstorage, but that only allows you to store something on browsers' internal storage (you cannot decide where and how to write data).

There's also a File API, but is at its very early stages and, by now, it doesn't allow to store files arbitrarily on the client:

HTML 5 File API

like image 23
mamoo Avatar answered Sep 22 '22 01:09

mamoo