0

I have the following line of code:

window.location.href = "data:text/csv;base64," + csvdata

that set to export csv data. it works on Mac with the extension "csv", but on windows it doesn't recognize as csv file. is there a way to specify the file extension?

1 Answer 1

1

Use navigator.msSaveBlob in IE, and .download for others.

 var blob = new Blob([csvdata], {
    type: "text/csv;charset=utf-8;"
  });
  var fileName = 'data.csv';

  if (window.navigator.msSaveOrOpenBlob) {
    navigator.msSaveBlob(blob, fileName);
  } else {
    var downloadLink = document.createElement("a");

    downloadLink.href = window.URL.createObjectURL(blob);
    downloadLink.download = fileName;

    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.