first post here, and hopefully it's not terrible. I'm looking to be able to download the contents of a textbox as an XML file; this textbox will contain XML the user posts. May not sound useful, but it will be. Anyways, this is the code I've got:
var rawXML = document.getElementById("rawCode").value;
var textFileAsBlob = new Blob([rawXML], {type:'text/plain'});
var fileNameToSaveAs = "deleteXML.xml";
var downloadLink = document.createElement("a");
console.log("XML prepped for download.");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
console.log("Download prepped.");
if (window.webkitURL != null)
{
// Chrome allows the link to be clicked
// without actually adding it to the DOM.
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
}
else
{
// Firefox requires the link to be added to the DOM
// before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
console.log("Download started.");
It works just fine on Chrome and Firefox, but IE hates it, doesn't do anything. Any ideas of alternative methods to use for IE? It doesn't like that
downloadLink.click();
line.