Javascript examples for DOM HTML Element:Anchor
Set <a> href to 'data:attachment/text,'
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from www. j a va 2s . c om*/ 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(); } </script> </head> <body> </body> </html>