var download = function () {
var content = 'abc';
var mimeType = 'text/plain';
var name = 'test.txt';
var bom = new Uint8Array([0xEF, 0xBB, 0xBF]);
var blob = new Blob([bom, content], {type : mimeType});
var a = document.createElement('a');
a.download = name;
a.target = '_blank';
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(blob, name)
}
else if (window.URL && window.URL.createObjectURL) {
a.href = window.URL.createObjectURL(blob);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
else if (window.webkitURL && window.webkitURL.createObject) {
a.href = window.webkitURL.createObjectURL(blob);
a.click();
}
else {
window.open('data:' + mimeType + ';base64,' + window.Base64.encode(content), '_blank');
}
}
document.getElementById('download').addEventListener('click', download);
<div id="download">Click to download</div>
#download {
display : block;
cursor : pointer;
background-color: #6DB7F7;
width : 180px;
line-height : 2em;
text-align : center;
}