Save text file on client machine using javascript

前端 未结 4 1532
别跟我提以往
别跟我提以往 2020-12-21 22:23

I want to create text file on client machine and then want to write in that file. And while saving that file i want to ask user where he want to save file i.e. want to ask b

相关标签:
4条回答
  • 2020-12-21 23:00

    You cannot write back using JavaScript alone. You would have to perform a GET or POST call to be able to prompt a save. Related question Read/write to file using jQuery

    0 讨论(0)
  • 2020-12-21 23:01

    That is not possible with JavaScript for security reasons. You cannot create files on the client machine, since JavaScript doesn't have write permission in that environment.

    What you could do as a work around is to send the text that you want to store through an Ajax-request to the web server, which in turn can generate a the text-file for the user to download to a desired location. Not as smooth, but at least it is a work around.

    0 讨论(0)
  • 2020-12-21 23:04

    You can do it through flash "proxy" that uses FileReference class and communicating with flash using ExternalInterface

    0 讨论(0)
  • 2020-12-21 23:13

    The data I wanted to write is already available at the client side (queried from server) and stored in Javascript arrays.

    I have done this using 'Data Tables' which is a plug-in for the jQuery Javascript library. You can store the data in .csv, excel or also .pdf. You can access this nice plug-in at http://datatables.net/

    0 讨论(0)
提交回复
热议问题