I am trying to transform a table to a csv file then download it, but I faced an issue while using Blob to download the csv document. The code snippet I am using to download the csv file is:
var elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
The issue is that the csv file is not downloading with the name I am assigning to the file. It uses a randomly generated name and with no extension. example of the file name after being downloaded: 43af43ac-7491-44ed-a779-a6c8f1972b1a.
I was able to fix this by removing the append() remove() functions. Consequently, I have two questions:
1- Why the issue is happening, and what is the best solution?
2- Why to append elem to the body of the HTML? And why the code worked after removing it?