[Resolved] Internet Explorer IE Download CSV file error open new tab instead of download the file

Internet Explorer IE Download CSV file error open new tab instead of download the file


Issue: download file error on the Internet Explorer 11

The function export the csv file is working normal on all browser except IE 11

On the IE 11, when I click download the file, browser open the new tab instead of download  the file as normally.

[Solved]:

Using the Blob download for the Internet Explorer 11(IE)

function goDevStackDownloadFile(csvFileNameWithExtension, fileContent) {

    var csvDataBlob = new Blob([decodeURIComponent(fileContent)], {

        type: 'text/csv;charset=utf-8'

    });

    if (window.navigator && window.navigator.msSaveOrOpenBlob) { // for IE

        window.navigator.msSaveOrOpenBlob(csvDataBlob, csvFileNameWithExtension);

    } else { // for Non-IE (chrome, firefox etc.)

        var aTag = document.createElement("a");

        document.body.appendChild(aTag);

        aTag.style = "display: none";

        var csvUrl = URL.createObjectURL(csvDataBlob);

        aTag.href = csvUrl;

        aTag.download = csvFileNameWithExtension;

        aTag.click();

        URL.revokeObjectURL(aTag.href);

        aTag.remove();

    }

}


I hope it can help.

Go Dev Stack


Post a Comment

Thank for leaving message

Previous Post Next Post
managed wordpress hosting
managed wordpress hosting