Creating a downloadable text-file using blobs with automatic download start
Created as part of my answer to http://stackoverflow.com/questions/8178825/create-text-file-in-javascript
HTML
<button id="create">Create file</button>
JavaScript
(function () {
var oldUrl = null,
makeObjectUrl = function (value) {
var data = new Blob([value], {type: 'application/pdf'});
// If we are replacing a previously generated file we need to
// manually revoke the object URL to avoid memory leaks.
if (oldUrl !== null) {
window.URL.revokeObjectURL(oldUrl);
}
oldUrl = URL.createObjectURL(data);
return oldUrl;
};
var create = document.getElementById('create'),
textbox = document.getElementById('textbox');
create.addEventListener('click', function () {
var pdfData =...