简体   繁体   English

使用Javascript下载XML文件在IE中不起作用

[英]XML file download using Javascript Not working in IE

Am trying to create XML file content and download it. 我正在尝试创建XML文件内容并下载。 For that I wrote code like this, 为此,我编写了这样的代码,

/* Preparing XML Data*/
var XML=new XMLWriter();
    XML.BeginNode("Root Node");
    XML.Attrib("ADIB", "Attribute");   
    XML.Node("Fullname", "Anil");
    XML.Node("D.O.B", "31/12/2015");
    XML.EndNode();
    XML.Close();

/* Downloading as XML file*/    
var data = XML.ToString().replace(/</g,"\n<");              
var a = document.createElement('a');
a.href= 'data:application/xml;charset=utf-8,' + encodeURIComponent(data);
a.target = '_blank';
a.download = 'New.xml';
a.click();

It is working in chrome but not in IE. 它在chrome中工作,但在IE中不工作。 Can you please help me. 你能帮我么。

It's because of differences with support of data URLS in common browsers. 这是因为常见浏览器中对数据URLS的支持存在差异。 You can check compatibility here: http://caniuse.com/#feat=datauri . 您可以在此处检查兼容性: http : //caniuse.com/#feat=datauri And as far as i know, IE has very limited ( https://msdn.microsoft.com/en-us/library/cc848897(v=vs.85).aspx ). 据我所知,IE的功能非常有限( https://msdn.microsoft.com/zh-cn/library/cc848897(v=vs.85).aspx )。

$("a").click(function(e){ $( “A”)。点击(函数(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));      
} });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM