在 Internet Explorer 中下载或显示 XML 文件
Download or display XML file in Internet Explorer
我有一个简单的 javascript 应用程序,它允许用户生成一些 XML 然后将其保存为文件。但是我无法在 IE 中工作。
目前我正在使用 data-uri
方法,如 this jsfiddle. But this does not work in IE because it does not support data-uri
中示例的 application/xml
。让用户轻松地将 xml 字符串(或 dom 节点)保存为文件的另一种方法或解决方法(仅限客户端)是什么?
匿名先生在评论中给出了正确答案
$("a").click(function(e){
var xml = $("textarea").text();
if(window.navigator && window.navigator.msSaveBlob){
e.preventDefault();
navigator.msSaveBlob( new Blob([xml], {type:'application/xml'}), "myfile.xml" )
} else {
$(this).attr("href", "data:application/xml," + encodeURIComponent(xml));
}
});
我有一个简单的 javascript 应用程序,它允许用户生成一些 XML 然后将其保存为文件。但是我无法在 IE 中工作。
目前我正在使用 data-uri
方法,如 this jsfiddle. But this does not work in IE because it does not support data-uri
中示例的 application/xml
。让用户轻松地将 xml 字符串(或 dom 节点)保存为文件的另一种方法或解决方法(仅限客户端)是什么?
匿名先生在评论中给出了正确答案
$("a").click(function(e){
var xml = $("textarea").text();
if(window.navigator && window.navigator.msSaveBlob){
e.preventDefault();
navigator.msSaveBlob( new Blob([xml], {type:'application/xml'}), "myfile.xml" )
} else {
$(this).attr("href", "data:application/xml," + encodeURIComponent(xml));
}
});