1// in the current page, download the html source
2var hiddenElement = document.createElement('a');
3hiddenElement.href = 'data:attachment/text,' + encodeURI(document.documentElement.outerHTML);
4hiddenElement.target = '_blank';
5hiddenElement.download = 'myFile.txt';
6hiddenElement.click();
1var textToSave = 'this is a test';
2
3var hiddenElement = document.createElement('a');
4
5hiddenElement.href = 'data:attachment/text,' + encodeURI(textToSave);
6hiddenElement.target = '_blank';
7hiddenElement.download = 'myFile.txt';
8hiddenElement.click();