简体   繁体   English

在iframe中生成XML +“保存”按钮

[英]Generate XML in iframe + “save”-button

Lets say that i have a valid xml string. 可以说我有一个有效的xml字符串。 Is there any way to put in an iframe and generate som kind of save button? 有什么方法可以放入iframe并生成som类的保存按钮? Either a link to the file, which you can right click on and use "save target as". 您可以右键单击该文件的链接,然后使用“将目标另存为”。 Or maybe the javascript function document.execCommand('SaveAs', true); 或者,可能是JavaScript函数document.execCommand('SaveAs', true); (since it will only need to work in IE). (因为它仅需要在IE中工作)。 Thanks 谢谢

You can make a server-side page that will output the data you want to save as the response body and by adding the header: 您可以制作一个服务器端页面,该页面将输出要保存为响应正文的数据,并添加标题:

content-disposition: attachment; filename=FILE_NAME.xml

this will make the browser open the save dialog for that file (you can name the file as you want by changing FILE_NAME 这将使浏览器打开该文件的“保存”对话框(您可以通过更改FILE_NAME来命名该文件

for example, with php you would do: 例如,使用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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM