在IE6中下载Javascript生成的XML [英] Download Javascript generated XML in IE6

查看:86
本文介绍了在IE6中下载Javascript生成的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Javascript让IE6下载文件。它将使用Javascript动态创建。 Web服务器上不存在此文件。这是一个小例子:

I'd like to use Javascript to make IE6 download a file. It'll be created on the fly using Javascript. This file doesn't exist on a webserver. Here's a small example:

<!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提示用户在哪里下载数据,以便它可以保存,而无需使用文件 - >另存为。任何想法?

Instead of loading the xml in the browser window, I want it to cause IE6 to prompt the user where to download the data to so that it can be saved without them having to use File -> Save as. Any ideas?

推荐答案

对于IE6,您应该可以使用 document.execCommand() c $ c> document.write():

For IE6 you should be able to use document.execCommand() after your document.write():

document.execCommand('SaveAs',true,'file.xml');

这不是任何标准的一部分,只适用于IE风味浏览器。

This is not part of any standard and will only work in IE flavor browsers.

这篇关于在IE6中下载Javascript生成的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆