function saveFile(filename, data) {
var blob = new Blob([data], {type:'text/plain'});
var saveLink = document.createElement("a");
saveLink.download = filename;
saveLink.innerHTML = "Save file";
if (window.webkitURL != null) {
saveLink.href = window.webkitURL.createObjectURL(blob);
} else {
saveLink.href = window.URL.createObjectURL(blob);
saveLink.onclick = destroyClickedElement;
saveLink.style.display = "none";
document.body.appendChild(saveLink);
}
saveLink.click();
}
function destroyClickedElement(event) {
document.body.removeChild(event.target);
}