【发布时间】:2019-02-19 10:24:00
【问题描述】:
我有一个 href 链接可以从我的应用程序中下载模板。它在 Chrome 和 IE 中运行良好,但在移动设备(Android 和 iPhone)中无法运行
我有这个函数,通过点击链接被调用..
fileUrl: any;
getFileTemplate(): any {
this.productService.getFile().subscribe((response) => {
const fileContent = response;
// An application or a document that must be opened in an application
const blob = new Blob([fileContent], { type: 'application/octet-stream' });
if (window.navigator.msSaveBlob) {
// to download in IE
window.navigator.msSaveBlob(blob, 'abcd.csv');
} else {
this.fileUrl= this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob));
const a = document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.download = 'abcd.csv';
a.click();
}
});
}
在 HTML 文件中
`<a href="javascript:void(null)"
(click)="getFileTemplate();"
id="link-inline-excel"
class="u-text--document u-text--document-link"
download="abcd.csv"><span>Title my file (7MB)</span></a>`
这不适用于移动设备。 我在这里错过了什么吗?
【问题讨论】:
-
在触发
click之前,您没有将创建的下载链接附加到DOM。 -
@Rikonator:: - 我到底需要怎么做?
标签: javascript angular angular6 mobile-devices