Javascript saveas dialog

↘锁芯ラ 提交于 2019-12-08 10:08:38

问题


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,

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

So my question is:

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

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>

回答1:


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.




回答2:


document.execCommand('SaveAs'...)

is not part of standard, and is not supported by all browsers. Better way to do this is to provide download link.



来源:https://stackoverflow.com/questions/5612373/javascript-saveas-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!