简体   繁体   English

使用javascript强制在IE7中下载文本文件

[英]Force a download of a text file in IE7 using javascript

Saw a similar question at Download a file using Javascript but this one is specific to IE and I'm using extjs and alfresco (opsoro). 使用Javascript下载文件时看到了类似的问题,但这是特定于IE的,我正在使用extjs和alfresco(opsoro)。 I can get a download prompt for text files fine in Opera, Chrome, and Firefox, but not IE. 我可以在Opera,Chrome和Firefox中得到很好的文本文件下载提示,但在IE中却没有。

Below is a list of what I've tried so far, which all work on other browsers except IE7. 以下是到目前为止我已经尝试过的内容的列表,这些内容都可以在除IE7之外的其他浏览器上使用。

document.location = downloadLocation; document.location = downloadLocation;

window.open(downloadLocation,'Download'); window.open(downloadLocation, '下载');

location.href = downloadLocation; location.href = downloadLocation;

When downloading other mimetypes (csv, xls), they download fine using any of the methods mentioned above. 当下载其他mimetypes(csv,xls)时,他们可以使用上述任何一种方法很好地下载。

You may need some help from the backend. 您可能需要后端的帮助。 Instead of serving the file statically, the backend app can load and serve the file contents with a content disposition header. 后端应用程序可以使用内容处理标头加载和提供文件内容,而不是静态提供文件。 That is guaranteed to invoke a download. 可以保证调用下载。

Content-disposition: attachment; filename=hello.txt

I don't know how you could do it with Alfresco, though. 不过,我不知道您如何使用Alfresco。

Edit: Wait! 编辑:等等! Check this out: http://forums.alfresco.com/en/viewtopic.php?f=36&t=21356&p=70252 检查一下: http : //forums.alfresco.com/en/viewtopic.php?f=36&t=21356&p=70252

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

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