Via Web API, download a blob file formatted as CSV to open in Excel. Code below works in Chrome and Firefox but not IE or Edge. Except, when I add the line "window.open(url)" which is shown below, it then opens in Edge but still not IE (but with this extra line Chrome then opens another tab that isn't necessary and doesn't even work but the file still downloads and opens). Hoping for answers on how to get this to work correctly in each of these browsers. Also get an 'Access is denied' message in IE and Edge but this message doesn't stop the file from downloading and opening via Edge with the extra line I mentioned.
var fileName = 'MovieList.csv';
var a = document.createElement("a");
a.style = "display: none";
var blob = new Blob([data], { type: "octet/stream" });
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
window.open(url);
window.URL.revokeObjectURL(url);