在IE

时间:2015-05-15 18:49:52

标签: javascript internet-explorer

首先发布在这里,希望它并不可怕。我希望能够将文本框的内容下载为XML文件;此文本框将包含用户发布的XML。可能听起来不是很有用,但它会。无论如何,这是我得到的代码:

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.");

它在Chrome和Firefox上运行得很好,但IE讨厌它,没有做任何事情。用于IE的替代方法的任何想法?它不是那样的

downloadLink.click();

线。

0 个答案:

没有答案