Data: paste / csv download does not work in Edge

I want to start the download after receiving certain data from the API. I do it as follows:

const anchor = window.angular.element('<a/>');
anchor.css({display: 'none'});
window.angular.element(document.body).append(anchor);

anchor.attr({
  href: 'data:attachment/csv;charset=utf-8,' + encodeURI(data),
  target: '_blank',
  download: 'somedata.csv',
})[0].click();

anchor.remove();

This approach works in both Chrome and Firefox. However, in Edge for some reason this is not so.

Why doesn't it work in Edge and how to fix it?

+4
source share

Source: https://habr.com/ru/post/1685740/


All Articles