Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
80
rated 0 times [  86] [ 6]  / answers: 1 / hits: 51985  / 12 Years ago, fri, may 18, 2012, 12:00:00

i want to create a text file from a string. currently i am using a function which takes an array and makes it into a string then using that string i want to create a local text file the user downloads.
i have tried using this method



   function createFile(){ //creates a file using the fileLIST list 
var output= 'Name t Statusn'+ fileLIST[0][0].name+'t'+fileLIST[0][1]+'n';
var Previous = fileLIST[0];
for (var i=1; i<fileLIST.length; i++)
if (fileLIST[i][1] =='none' || fileLIST[i][1] == Previous[1])
continue
else {
Previous = fileLIST[i]
output = output + fileLIST[i][0].name +'t'+fileLIST[i][1] + 'n';}

window.open(data:text/json;charset=utf-8, + escape(output));//should create file
display(); }


i am using chrome as my browser. also i would prefer JS or HTML5 answer.



thank you in advance


More From » html

 Answers
46

i ended up using this code instead. it creates a link to download the url of the file.



     window.URL = window.webkitURL || window.URL;
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
file = new WebKitBlobBuilder();
file.append(output);
var a = document.getElementById(downloadFile);
a.hidden = '';
a.href = window.URL.createObjectURL(file.getBlob('text/plain'));
a.download = 'filename.txt';
a.textContent = 'Download file!';
}


also this way adds less to the website making it a lighter website for slow connections.
my html has a empty div in which this appends to.



   <div class ='paginationLIST' id='pagination'></div>

[#85493] Thursday, May 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
corie

Total Points: 371
Total Questions: 110
Total Answers: 113

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
corie questions
Mon, Feb 22, 21, 00:00, 3 Years ago
Tue, Sep 1, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
Sun, Jun 9, 19, 00:00, 5 Years ago
;