Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

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();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #set #var #js #download
ADD COMMENT
Topic
Name
8+9 =