Navigating to a Data URI in IE

社会主义新天地 提交于 2019-12-07 12:59:28

问题


I have this extremely simple HTML:

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

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

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

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.

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.


Edit: MSDN says:

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.


回答1:


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.

Credit goes to this answer.



来源:https://stackoverflow.com/questions/29037162/navigating-to-a-data-uri-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!