js调用浏览器下载

时间:2020-12-28 16:46:45
 1  $scope.Download = function (url) {
 2             var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
 3             //地址
 4             save_link.href = url;
 5             save_link.download = name;
 6             var ev = document.createEvent("MouseEvents");
 7             ev.initMouseEvent(
 8                 "click", true, false, window, 0, 0, 0, 0, 0
 9                 , false, false, false, false, 0, null
10             );
11             save_link.dispatchEvent(ev);
12         }
13     }