Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  76] [ 3]  / answers: 1 / hits: 191624  / 12 Years ago, thu, july 5, 2012, 12:00:00

How can I make a browser display a save as dialog so the user can save the content of a string to a file on his system?



For example:



var myString = my string with some stuff;
save_to_filesystem(myString,myString.txt);


Resulting in something like this:



Example


More From » save

 Answers
52

EDIT 2022: Please see other answers regarding File System API




In case anyone is still wondering...


I did it like this:


<a href="data:application/xml;charset=utf-8,your code here" download="filename.html">Save</a>

can't remember my source but it uses the following techniquesfeatures:



  1. html5 download attribute

  2. data URI's


Found the reference:


http://paxcel.net/blog/savedownload-file-using-html5-javascript-the-download-attribute-2/




EDIT:
As you can gather from the comments, this does NOT work in



  1. Internet Explorer (however works in Edge v13 and later)

  2. Opera Mini


http://caniuse.com/#feat=download


[#84461] Tuesday, July 3, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylanalis

Total Points: 438
Total Questions: 85
Total Answers: 102

Location: Barbados
Member since Sun, Nov 27, 2022
1 Year ago
kylanalis questions
Sat, Oct 2, 21, 00:00, 3 Years ago
Tue, Oct 13, 20, 00:00, 4 Years ago
Thu, Feb 13, 20, 00:00, 4 Years ago
Tue, Jan 7, 20, 00:00, 4 Years ago
;