Reputation: 35194
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var xml = '<?xml version="1.0"?><foo><bar>bar</bar></foo>';
document.open("text/xml", "replace");
document.write(xml);
document.execCommand('SaveAs',true,'file.xml');
});
</script>
</head>
<body>
</body>
</html>
This html-file generates an xml file (in IE) and creates a "save as" dialog. However, I would like to reset the document to its previous state (before the "replace") after I have saved the file. Is this possible using pure javascript or jQuery? Thanks
Upvotes: 0
Views: 985
Reputation: 8154
Maybe do it all in a popup window?
$(function(){ var popup = window.open() var xml = 'bar';
popup.document.open("text/xml", "replace");
popup.document.write(xml);
popup.document.execCommand('SaveAs',true,'file.xml');
popup.close();
});
Upvotes: 0
Reputation: 769
simply no because document.open() clears the document. you should do what SLaks says.
read it https://developer.mozilla.org/en/DOM/document.open
Upvotes: 0
Reputation: 21830
You don't need to save the entire dom. Just save the values of what can change (form fields and other small UI bits that are communicative) and update those when necessary.
If necessary, write a reset function that you can call whenever you need it.
Upvotes: 0
Reputation: 887453
Run that code against the document
from an <iframe>
instead of replacing the current document.
Upvotes: 1