Last active
August 29, 2015 14:26
-
-
Save TechplexEngineer/1bd64a2ff0768a9be411 to your computer and use it in GitHub Desktop.
Javascript to download text as a file. Demo: http://jsfiddle.net/TechplexEngineer/geLvp6bo/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function download (text, filename) { | |
| if (typeof filename === "undefined") { | |
| filename = false; | |
| }; | |
| var pom = document.createElement('a'); | |
| pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | |
| if (filename) { | |
| pom.setAttribute('download', filename); | |
| } | |
| pom.click(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment