有什么方法可以模仿锚标签的下载属性?

Any way to mimic the download attribute of an anchor tag?

<a> 标签的 download 属性有助于 Edge (即,一旦意识到不会使用,它就会关闭目标选项卡)。当 Javascript 负责启动下载时,有什么办法可以做到这一点吗?如

HTML:

<span class='btn-link' onclick='openReport(@orderNumber, @tableBodyId); return false;'>

Javascript(与 ASP.NET MVC 控制器对话):

function openReport(orderNumber, tableBodyId) {
    var url = "/Reports/ValuationReportDocPdf?orderNumber=" + orderNumber;
    var win = window.open(url, '');
    setTimeout(function () { location.reload(); }, 3000);
}

我不知道有任何 Javascript 功能或设置可以让您在下载时更改文件名,或者任何模仿 <a> 标签上的 download 属性的功能或设置。

在类似的问题中,this answer by user3758133 概述了一种解决方法,您可以在其中以编程方式创建 link,附加正确的 download 属性并触发点击:

("#downloadbutton").click(function() {
  //var content = content of file;
  var dl = document.createElement('a');
  dl.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(content));
  dl.setAttribute('download', 'filename.txt');
  dl.click();
});