Answers for "how to set a var in js to be a download"

0

how to set a var in js to be a download

var textToSave = 'this is a test';

var hiddenElement = document.createElement('a');

hiddenElement.href = 'data:attachment/text,' + encodeURI(textToSave);
hiddenElement.target = '_blank';
hiddenElement.download = 'myFile.txt';
hiddenElement.click();
Posted by: Guest on March-25-2020

Code answers related to "how to set a var in js to be a download"

Browse Popular Code Answers by Language