我有一个简单的 JavaScript 应用程序,可以让用户生成一些 XML,然后将其保存为文件。但是我无法在 IE 中使用保存的内容。
目前我正在使用 data-uri
方法,如 this jsfiddle 中所示。 。但这在 IE 中不起作用,因为它 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 - 在 Internet Explorer 中下载或显示 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28686843/