0

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.

friedbunny
  • 2,421
  • 1
  • 23
  • 38
  • try this method http://stackoverflow.com/questions/2489528/how-do-i-dynamically-create-a-document-for-download-in-javascript – vlatkokaplan May 15 '15 at 18:53
  • I gave that a go, but all it seems to do is open a new, blank tab. Downloadify looks nice, but it's not hosted online, but run locally instead... – silentArtifact May 15 '15 at 19:50

0 Answers0