数据 URI 不适用于 IE [英] Data URI doesn't work with IE
问题描述
我正在尝试使用用户可以下载的 javascript 动态创建 CSV 文件.这只能在 IE 中工作.
Im trying to dynamically create a CSV file using javascript that the user can download. This only has to work in IE.
javascript 生成的 html 看起来像这样
The html the javascript generates looks something like this
<a href="data:application/octet-stream,field1%2Cfield2%0Afoo%2Cbar%0Agoo%2Cgai%0A">CSV</a>
哪个接缝在 chrome 中可以正常工作,但 IE10 就坏了.
Which seams to work fine in chrome but IE10 just breaks.
是否有更好的方法来使用 JavaScript 动态创建文件,然后为用户提供下载链接?由于用户设置的限制,我无法使用 PHP,因为整个系统需要在客户端运行.系统都需要在触摸屏上工作(没有右键单击选项),因此链接需要让用户能够下载,而不是打开文件.
Is there a better way to dynamically create a file using JavaScript and then give the user a link to download it? I cant use PHP as the entire system needs to run on the client-side due to restrictions placed by the user. The system all needs to work on a touch screen (with no right click option) so the link needs to give the user the ability to download, not open the file.
推荐答案
Internet Explorer 10 不支持 a
元素上的 data
协议.根据文档,唯一支持的元素/属性如下:
Internet Explorer 10 doesn't support the data
protocol on the a
element. Per the documentation, the only supported elements/attributes are the following:
- 对象(仅限图像)
- img
- 输入类型=图像
- 链接
- 接受 URL 的 CSS 声明,例如 background、backgroundImage 等.
您应该知道您尝试做的事情闻起来像是网络钓鱼;出于这个原因,您不应该期望浏览器支持这种模式.您可以在论文 通过数据 URI 进行网络钓鱼 中阅读有关数据 uri 网络钓鱼的更多信息.
You should know that what you're attempting to do smells like a phishing attempt; for this reason you shouldn't expect browsers to support this pattern. You can read more about data-uri phishing in the paper Phishing by data URI.
这篇关于数据 URI 不适用于 IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!