function download(title, text) { var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', title); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); }