How to Save a file at client side using JavaScript?

前端 未结 6 558
一生所求
一生所求 2020-12-11 06:44

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,\" + es

6条回答
  •  鱼传尺愫
    2020-12-11 07:16

    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 information with other browsers on the same machine this way. Also, I doubt many users change their browser too frequently anyway to warrant a privacy-invasive feature like this. You should either consider storing the information on your server (by forcing a user to register or using common accounts like OpenID, Google, Facebook etc.) 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.

    Update: Flash isn't supported by browsers as it used to be and not widely used nowadays, so LSOs aren't a good option any more.

提交回复
热议问题