I have a simple javascript application that lets the user generate some XML and then save it as a file. However I can't get the saving to work in IE.
Currently I am using the data-uri
method as exemplified in this jsfiddle. But this does not work in IE because it does not support data-uri
for application/xml
. What would be another method or workaround (client-only) to let the user easily save an xml string (or dom node) as a file?
The correct answer was given by Mr Anonymous in the comment.
$("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));
}
});