How to Save a file at client side using JavaScript?

前端 未结 6 551
一生所求
一生所求 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:04

    As has already been mentioned in the comments, this is not possible without express user consent for obvious security reasons. however, as also mentioned in comments, you shoudl/could store the information in a cookie which will then be retrievable when the user returns.

    something like this would do it

    document.cookie="cookie_name="+required_value+"; expires=Monday, 04-Dec-2011 05:00:00 GMT";
    

    obviously the expires time will be as long as you need the information to persist.

    hope that helps

提交回复
热议问题