简体   繁体   English

HTML5下载属性…有时文件名是通用的Download.xlsx

[英]Html5 download attribute…sometimes file name is generic Download.xlsx

I am using Chrome Dev and Chrome canary and the filename of the downloaded file sometimes is called Download.xlsx instead of what I name it. 我使用的是Chrome Dev和Chrome Canary,下载文件的文件名有时称为Download.xlsx,而不是我的名字。

Sometimes it works great, othertimes its the wrong file name 有时效果很好,有时文件名错误

I am created a detached dom node and firing it 我创建了一个独立的dom节点并将其解雇

var link = document.createElement('a');
        angular.element(link)
            .attr('download', response.data.fileDownloadName)
            .attr('href', 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,' + response.data.fileContents);
        link.click();

rendered html: 呈现的html:

<a download="Report.xlsx" href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,UEsDBBQAAAAIAAAAIQD8JIb71AIAA...

The behaviour your describe happens if response.data.fileDownloadName is undefined . 如果response.data.fileDownloadName undefined则会发生您描述的行为。 In that case the generated filename will be download.extension . 在这种情况下,生成的文件名将是download.extension Note however that this would be with a lowercase d at least in chrome unlike the D you mention in your question. 但是请注意,与您在问题中提到的D不同,这至少在chrome中使用小写d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM