Javascript generate client-side file for download

Date: 2019-09-30

https://stackoverflow.com/a/33542499

function saveFile(filename, type, data) {
// type: 'text/csv'
    var blob = new Blob([data], {type: type});
    if(window.navigator.msSaveOrOpenBlob) {
        window.navigator.msSaveBlob(blob, filename);
    }
    else{
        var elem = window.document.createElement('a');
        elem.href = window.URL.createObjectURL(blob);
        elem.download = filename;        
        document.body.appendChild(elem);
        elem.click();        
        document.body.removeChild(elem);
    }
}

26120cookie-checkJavascript generate client-side file for download