, : Blob, createObjectURL() anchor.
JSFiddle , Chrome Internet Explorer, Chrome ( "" Windows, .) http://jsfiddle.net/fa9y6/9/
Blob :
var blob = new Blob([ $('#documentContent').val() ], { type: mimeType });
Internet Explorer:
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, filename);
}
Chrome ( Firefox) anchor click() it:
var a = document.createElement('a');
a.download = filename;
a.href = window.URL.createObjectURL(blob);
a.click();
if (a.remove) a.remove();
, dragstart:
if (window.chrome) {
document.body.addEventListener('dragstart', function(e) {
if (e.target.id == 'downloadButton') {
var blob = new Blob([ $('#documentContent').val() ], { type: mimeType });
e.dataTransfer.setData('DownloadURL', [mimeType, $('#fileName').val(), window.URL.createObjectURL(blob)].join(':'));
}
});
}
( .)