Ciao,
probabilmente non ho capito cosa vuoi fare, ma a me non sembra impossibile farlo in javascript
Una cosa del genere:
Qui un esempio funzionante in chrome.codice:<textarea id='txtArea'>Ciao da U235!</textarea> .... var txtArea = document.getElementById('txtArea'); var txt = txtArea.value; var fileB64 = window.btoa(txt); var saveFile = (function () { var a = document.createElement("a"); document.body.appendChild(a); a.style = "display: none"; return function (data, name) { var blob = new Blob(data, { type: "octet/stream" }), url = window.URL.createObjectURL(blob); a.href = url; a.download = name; a.click(); window.URL.revokeObjectURL(url); }; }()); //trasformi in array di byte var binFile = window.atob(fileB64); var bytes = new Uint8Array(binFile.length); for (var i = 0; i < binFile.length; i++) { var ascii = binFile.charCodeAt(i); bytes[i] = ascii; } //fai aprire la finestra di download saveFile([bytes], 'test.txt');
P.S.
Volendo se si tratta di testo puoi anche non trasformarlo in base 64:
codice:var txtArea = document.getElementById('txtArea'); var txt = txtArea.value; var saveFile = (function () { var a = document.createElement("a"); document.body.appendChild(a); a.style = "display: none"; return function (data, name) { var blob = new Blob(data, { type: "octet/stream" }), url = window.URL.createObjectURL(blob); a.href = url; a.download = name; a.click(); window.URL.revokeObjectURL(url); }; }()); //trasformi in array di byte var bytes = new Uint8Array(txt.length); for (var i = 0; i < txt.length; i++) { var ascii = txt.charCodeAt(i); bytes[i] = ascii; } //fai aprire la finestra di download saveFile([bytes], 'test.txt');

Rispondi quotando