Another way to do this is to use Blob and URL.createObjectURL . All recent browsers, including Safari 6+, support them.
var textFile = null, makeTextFile = function (text) { var data = new Blob([text], {type: 'text/plain'});
Here is an example that uses this method to save arbitrary text from textarea .
One more note that I used the download attribute in the download link. Unfortunately, Safari does not currently support it. However, in browsers, the file is automatically loaded when clicked, and not in opening the file in the browser. In addition, since I set the download attribute to info.txt , the file will be loaded with that name instead of the random name generated by createObjectURL .
Useless code
source share