Skip to main content
Topic: javascript textarea file donwload problem (Read 773 times)

javascript textarea file donwload problem

hi all, some javascript code under...
it allow to donwload the "value" of an textarea as a file
but, the anchor.donwload = "mydata.txt" do not works on Otter, with chromium-likes no problem...
the title of the file is a zvcgdfrtebvnfhgrtuz[...]gdfezzzbrter kind of name...
it's easy to change into the downloader form, but the width of the name file(too large) make this download just uggly...

somes may got a solution, or... an idea ?
(but it work
Code: [Select]
function filedownload(){
var text = document.getElementById("mytextarea").value;
var blob = new Blob([text], { type: "text/plain"});
var anchor = document.createElement("a");
anchor.download = "mydata.txt";
anchor.href = window.URL.createObjectURL(blob);
anchor.target ="_blank";
anchor.style.display = "none"; // just to be safe!
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor); }