Answer the question
In order to leave comments, you need to log in
Why is the file not saved by getElementById?
This code
document.getElementsByTagName('a')[0].onclick = function() {
var csv = "A";
var csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
this.href = csvData;
this.target = '_blank';
this.download = 'filename1.csv';
}
works, the file is saved, and this onedocument.getElementById('btn').onclick = function() {
var csv = "BUTTON";
var csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
this.href = csvData;
this.target = '_blank';
this.download = 'filename2.csv';
}
no. Answer the question
In order to leave comments, you need to log in
Take a closer look at the code. The script simply takes and sets the link href with csvData value. After that, the browser, not understanding the format, downloads it. Why the hell does a button have a href attribute?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question