Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
17
rated 0 times [  18] [ 1]  / answers: 1 / hits: 17370  / 13 Years ago, sun, january 1, 2012, 12:00:00

I want to write a localStorage item to a text file and want to invoke user to store the file in a specified location. Please help me with extending the code



  var data = JSON.parse(localStorage.getItem(pid));   
var Text2Write = ;
for(var pr in ele)
{
var dat = pr + : + ele[pr] + n;
Text2Write += dat;
}
// Here I want to store this Text2Write to text file and ask user to save where he wants.


Please help me extending this code.


More From » html

 Answers
89

If you don't want to use a server-side solution (does not have to be PHP of course), the easiest way is to use a data URI:



data:text/plain,Your text here


This will show the text file in the browser, and let the user save it where they want. I don't think it's possible to show a Save as-dialog for those kind of URI:s.



Note: this requires IE8 at least. But I'm guessing that's your requirement anyway, since you are using localStorage.


[#88289] Friday, December 30, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondd

Total Points: 620
Total Questions: 112
Total Answers: 94

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
raymondd questions
Thu, Apr 22, 21, 00:00, 3 Years ago
Thu, Jul 9, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
Thu, Jul 25, 19, 00:00, 5 Years ago
;