javascript Internet Explorer 中的替代 btoa 编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18508582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
alternative btoa encoding in Internet Explorer
提问by user2728834
I am trying to implement the same code from http://jsbin.com/ufufez/1/editinto my environment and it's not working in IE. Can someone give an alternate solutions for this to make it work in IE > 8.
我正在尝试将http://jsbin.com/ufufez/1/edit 中的相同代码实现到我的环境中,但它在 IE 中不起作用。有人可以为此提供替代解决方案以使其在 IE > 8 中工作。
回答by Yogesh Manware
window.btoa() is not supported on <= IE9.
<= IE9 不支持 window.btoa()。
There are few more alternatives but I guess you can use jQuery.base64.js
as below
还有更多的选择,但我想你可以使用jQuery.base64.js
如下
if (window.btoa) {
msg.dataEncoded = window.btoa(msg.data);
} else { //for <= IE9
msg.dataEncoded = jQuery.base64.encode(msg.data);
}
回答by Jan Turoň
This is not a problem with btoa()
(the code works fine in IE8) but with data scheme support and it won't workin IE 8:
这不是问题btoa()
(代码在 IE8 中工作正常),但有数据方案支持,它在 IE 8 中不起作用:
The data scheme is supported by Opera 7.20 and above, as well as Safari and Konqueror. Internet Explorer 7 and below, however, do not currently support it. Internet Explorer 8 and above only supports data URIs for images in CSS, <link>, and <img>
Opera 7.20 及以上版本以及Safari 和Konqueror 均支持该数据方案。但是,Internet Explorer 7 及以下版本目前不支持它。Internet Explorer 8 及更高版本仅支持 CSS、<link> 和 <img> 中图像的数据 URI
Therefore, <a href="data:text/xml;base64,...">download</a>
won't launch the download in IE8.
因此,<a href="data:text/xml;base64,...">download</a>
不会在 IE8 中启动下载。
To make it work in IE8, you need to solve it on the server side (create a temporary xml file there and create a standard link to it without the data scheme).
要使其在 IE8 中工作,您需要在服务器端解决它(在那里创建一个临时 xml 文件并创建一个没有数据方案的标准链接)。