javascript - 在 IE6 中下载 Javascript 生成的 XML

标签 javascript

我想使用 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/

相关文章:

javascript - 在 Ruby Slim 文件中设置 Javascript 类型

javascript - 是否可以推迟属性(property)的值(value)但之前使用它?

javascript - 在数组js中根据条件进行归约

javascript - 从 SEO Angular 考虑加载图像 onLoad 是否有益?

javascript - 更改脚本 : Loop through divs every 10 seconds PLUS select DIV

javascript - bootstrap - bootstrap 仅在调整大小后工作

javascript - Firefox -- 在 SVG 中动态嵌入 <svg> 元素

javascript - 未设置 Node process.timezone

javascript - 使用 Javascript 在 TEXTAREA 中隐式折叠

javascript - "cannot read property length of null"- 谷歌