Javascript 在iframe+中生成XML&引用;“保存”-按钮

Javascript 在iframe+中生成XML&引用;“保存”-按钮,javascript,jquery,html,internet-explorer,iframe,Javascript,Jquery,Html,Internet Explorer,Iframe,假设我有一个有效的xml字符串。有没有办法放入iframe并生成som类型的保存按钮?或者是指向该文件的链接,您可以右键单击该文件并使用“另存目标为”。或者javascript函数document.execCommand('SaveAs',true)(因为它只需要在IE中工作)。谢谢您可以创建一个服务器端页面,该页面将输出您要保存为响应正文的数据,并通过添加标题: content-disposition: attachment; filename=FILE_NAME.xml 这将使浏览器打开该

假设我有一个有效的xml字符串。有没有办法放入iframe并生成som类型的保存按钮?或者是指向该文件的链接,您可以右键单击该文件并使用“另存目标为”。或者javascript函数
document.execCommand('SaveAs',true)(因为它只需要在IE中工作)。谢谢

您可以创建一个服务器端页面,该页面将输出您要保存为响应正文的数据,并通过添加标题:

content-disposition: attachment; filename=FILE_NAME.xml
这将使浏览器打开该文件的“保存”对话框(您可以通过更改文件名来命名文件)

例如,使用php,您可以执行以下操作:

$data = file_get_contents("1.xml"); //set the data you want to output to this variable
header("content-disposition: attachment; filename=my_xml.xml");
header("content-length: ".filesize("1.xml"));
echo $data;

通过添加标题,您可以创建一个服务器端页面,该页面将输出要另存为响应正文的数据:

content-disposition: attachment; filename=FILE_NAME.xml
这将使浏览器打开该文件的“保存”对话框(您可以通过更改文件名来命名文件)

例如,使用php,您可以执行以下操作:

$data = file_get_contents("1.xml"); //set the data you want to output to this variable
header("content-disposition: attachment; filename=my_xml.xml");
header("content-length: ".filesize("1.xml"));
echo $data;