我想使用 Javascript 让 IE6 下载文件。它将使用 Javascript 即时创建。该文件在网络服务器上不存在。这是一个小例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript">
function clicked() {
var xml = "<data>Just for testing</data>";
document.open("text/xml", "replace");
document.write(xml);
}
</script>
</head>
<body>
<input type="button" value="Download" onclick="clicked();" />
</body>
</html>
我希望它不是在浏览器窗口中加载 xml,而是让 IE6 提示用户将数据下载到何处,以便无需使用文件 -> 另存为即可保存数据。有什么想法吗?
最佳答案
对于 IE6,您应该可以使用 document.execCommand()
在你的 document.write()
之后:
document.execCommand('SaveAs',true,'file.xml');
这不是任何标准的一部分,只能在 IE 风格的浏览器中使用。
关于javascript - 在 IE6 中下载 Javascript 生成的 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1067162/