I am using the following code to create a text file from the browser. It works when I'm using data:text/plain;charset=utf-8, and the text is plain but when the data is xls, I get a network error and it doesn't work. Can anyone advise me what I'm missing or doing wrong.
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:application/xls;base64,'+text);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
console.log(text);
document.body.removeChild(element);
}
I should note, the code has come from https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server
Thanks in advance.
I don't want to use BLOBS.