Javascript saveas对话框 [英] Javascript saveas dialog

查看:112
本文介绍了Javascript saveas对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javascript编写另存为对话框,

I am trying to write save as dialog with javascript,

我有一个数据内容,我想让用户保存它,

I have a content of data, and I want to allow the user to save it,

我设法让下面的代码工作,但是这段代码正在改变html数据,

I managed to get the code below to work, but this code is changing the html data,

所以我的问题是:

1)我如何重新获取html数据,就像点击按钮之前一样?

1)How can I retrived the html data back, as it was before I the click on the button?

2)我能以更优雅的方式做到吗?

2)Can I do it more elegant way?

<script type="text/javascript">
function saveChanges()
{

var oldHtml = document.documentElement;
document.open("text/html","replace");
document.write("Hello");
document.close();
document.execCommand("saveas", false, "default.htm");
}
</script>

<body>
<button onclick="saveChanges();">Click to save123</Button>
</body>


推荐答案

通常的做法是提供下载链接,当单击时,使服务器返回 Content-Disposition:attachment 标头集的结果。

The usual way to do it is to provide a download link which, when clicked, makes the server return a result with the Content-Disposition: attachment header set.

这篇关于Javascript saveas对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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