数据URI不适用于IE [英] Data URI doesn't work with IE

查看:108
本文介绍了数据URI不适用于IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用JavaScript动态创建一个CSV文件,用户可以下载。这只需要在IE中工作。



javascript生成的html看起来像这样

 <一个href =data:application / octet-stream,field1%2Cfield2%0Afoo%2Cbar%0Agoo%2Cgai%0A> CSV< / a> 

哪个接口可以在Chrome中正常工作,但IE10会中断。

有没有更好的方式使用JavaScript动态创建文件,然后给用户一个链接来下载它?由于用户的限制,我无法使用PHP,因为整个系统需要在客户端运行。系统都需要在触摸屏上工作(没有右键单击选项),因此链接需要让用户能够下载,而不是打开文件。

解决方案

Internet Explorer 10不支持数据协议 a 元素。根据文档,唯一支持的元素/属性是以下内容:


  • 对象(仅限图片)

  • img

  • input type = image

  • link

  • 接受URL的CSS声明,如background,backgroundImage等。



您应该知道您试图做的事情有如网络钓鱼尝试的味道;出于这个原因,你不应该指望浏览器支持这种模式。您可以在纸张网络钓鱼阅读更多有关数据URI的网络钓鱼数据URI


Im trying to dynamically create a CSV file using javascript that the user can download. This only has to work in IE.

The html the javascript generates looks something like this

 <a href="data:application/octet-stream,field1%2Cfield2%0Afoo%2Cbar%0Agoo%2Cgai%0A">CSV</a>

Which seams to work fine in chrome but IE10 just breaks.

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 doesn't support the data protocol on the a element. Per the documentation, the only supported elements/attributes are the following:

  • object (images only)
  • img
  • input type=image
  • link
  • CSS declarations that accept a URL, such as background, backgroundImage, and so on.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆