Javascript saveas dialog
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?
&开发者_JAVA技巧lt;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>
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.
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.
精彩评论