aProgrammer aProgrammer - 3 years ago 196
jQuery Question

How to Save a file at client side using JavaScript?

I want to save a JSON object to a file at client to persist it for future usage, I have tried following line

window.open("data:text/json;charset=utf-8," + escape(JSON.stringify(obj)));

and it works!! Problem it asks user the location and name of the file for saving. What I want is I want the user completely unaware of the fact that something is being saved for future use or atleast keep it to minimum possible user clicks.

How can I give the file name and location statically in

Thanks in advance,


Just to make it clear that " I don't store arbitrary or unwanted data. All the users are registered users of the system." In normal conditions I don't store anything locally. However I want to store some JSON objects if the network was not available at the time of form submission.

One obvious solution will be to use cookies. Since Cookies can be accidentally deleted due to user's browser settings. I need a way to persist the data till the network becomes available. It will be greater to have cross browser support.

Answer Source

I want the values for cross-browser support, even if the user changes the browser he/she should be able to proceed from where he left. I am storing information in JSON objects.

I think users don't expect a web application to share informations just with other browsers on the same machine this way. Also, I doubt many users change their browser too frequently anyway. You should either consider storing the information on your server (by forcing a user to register or using common accounts like openID, google or facebook) or on the client side by setting a cookie or using the mentioned storage technologies.

If you really want to restrict stored information to browsers on the same machine, and don't want to permit access by the same user on different machines, you could take a look into LSO ('Flash cookies') which seem to be saved browser independent. You don't need any user confirmation for storing LSOs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download