Javascript examples for DOM HTML Element:Anchor
Create download <a> link
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from ww w. j a va2 s. co m 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>