Javascript 设置window.location下载文件时出现警告

Javascript 设置window.location下载文件时出现警告,javascript,download,http-accept-header,Javascript,Download,Http Accept Header,我正在将window.location设置为下载文件(“/foo/bar”)。现在,下载在google chrome中运行,但它发出以下警告: Resource interpreted as Document but transferred with MIME type application/csv: 以下是根据google chrome设置的响应标题: Content-Description:File Transfer Content-Disposition:attachment; f

我正在将window.location设置为下载文件(“/foo/bar”)。现在,下载在google chrome中运行,但它发出以下警告:

Resource interpreted as Document but transferred with MIME type application/csv:
以下是根据google chrome设置的响应标题:

Content-Description:File Transfer  
Content-Disposition:attachment; filename="foo.csv"  
Content-Length:29  
Content-Type:application/csv
Date:Sun, 14 Dec 2014 20:53:33 GMT  
Server:http-kit  

如果我可以在js端设置accept头以忽略此警告,您有什么想法吗?

您可以使用锚定标记

<a href="fileLink" download="filename">Download</a>


请确保在“下载”属性中输入文件的扩展名类型,如.html、.css、.js,不管它是什么

,但我根本没有链接。我正在做一个ajax请求,然后设置window.location.create一个动态的?使用javascript document.createElement('a'),然后通过js触发对链接的单击?我以前从来没有这样做过,但听起来可能有用。var downloadLink=document.createElement('a');downloadLink.href=“fileLink”;downloadLink.download=“fileName”;我相信链接必须在文档上,所以:document.body.appendChild(downloadLink);downloadLink.click();仍然尝试看看如何使用url,这样就不必弄乱dom。也可以在window.open上查找以下载文件