导航到IE中的数据URI [英] Navigating to a Data URI in IE

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

问题描述

我有这个非常简单的HTML:

I have this extremely simple HTML:

<a download="red.png"
   href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==">
   Static
</a>

在Chrome或Firefox中,它会按预期下载red.png.

In Chrome or Firefox, it downloads red.png as expected.

在IE中,它导航到错误页面.在 JSFiddle 上查看.

In IE, it navigates to an error page. See it on JSFiddle.

现在,我知道IE中不支持download属性,这很好.我仍然希望它能够导航到文件",从而允许用户保存它.相反,它导航到错误页面.

Now, I know the download attribute is not supported in IE, and that's fine. I'd still expect it to navigate to the "file", allowing the user to save it. Instead, it's navigating to an error page.

有没有办法解决这个问题?数据URI是在客户端生成的;在服务器上创建文件不是一种选择.

Is there a way to get around this problem? The Data URI is generated client-side; creating the file on the server is not an option.

MSDN说:

出于安全原因,数据URI仅限下载 资源.数据URI不能用于导航,脚本编写或 填充框架或iframe元素.

For security reasons, data URIs are restricted to downloaded resources. Data URIs cannot be used for navigation, for scripting, or to populate frame or iframe elements.

...我读为即使其他所有浏览器都支持此功能,我们也不知道该怎么做".因此,仍在寻找一种变通方法来下载在客户端上生成的文件.

...which I read as "Even though every other browser supports this, we don't know how to do it". So, still looking for a workaround to download a file generated on the client.

推荐答案

由于IE不支持导航到数据URI,也不支持download属性,因此解决方案是使用navigator.msSaveBlob生成文件并提示用户保存它.

Since IE does not support either navigating to a data URI, nor the download attribute, the solution is to use navigator.msSaveBlob to generate the file and prompt the user to save it.

信用转到此答案.

这篇关于导航到IE中的数据URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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