2

Internet Explorer (all versions) appears to completely disregard any changes made to the DOM when you use the Save As command, reverting the saved version to the state of the webpage on first load. This affects javascript apps where you are trying to save a snapshot of the app's current state.

In this following trivial example, when you load the page, a random number appears. Saving this page in Firefox or Chrome results in that number being FIXED in the resulting saved document (because next time you open it, the .generateRandomNumber span has been deleted and overwritten, so the JS is not executed).

<!DOCTYPE HTML>
<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">
    jQuery(function($) {
        if ($('.generateRandomNumber').length) {
            var randomNumber = Math.round(Math.random() * 1000);
            $('.generateRandomNumber').remove();
            $('body').html(randomNumber);
        }
    });
    </script>
</head>
<body>
    <span class="generateRandomNumber"></span>
</body>
</html>

You can also see the behaviour by doing the following from the IE console:

var w = window.open();
w.document.body.innerHTML = "Hello world. Please save me";

Another simple example would be to run the following script to any page (from IE dev console). Run it, watch the HTML get wiped, save it, open the saved version and see the original site reappear.

document.body.innerHTML = "";

Save that new document, and the text will be gone when you next open it.

I've reviewed the following pages, but now found any solution:

Save the document generated by javascript

http://dsgdev.wordpress.com/2006/09/27/save-as-real-data-when-the-page-is-generated-with-javascript-documentwrite/

Any help would be much appreciated.

Community
  • 1
  • 1
Simon Lang
  • 40,171
  • 9
  • 49
  • 58
  • While an interesting question, saving pages through Save As... is in no way, shape or form I'm aware of standardized nor required at all. As such, you're probably simply out of luck of you expect this to work consistently across browsers. – deceze Feb 09 '12 at 04:53
  • Any suggestion for a workaround? I'm thinking the only workaround will require a server, and this app has to work offline. – Simon Lang Feb 09 '12 at 04:54

1 Answers1

2

If you hit F12, the developer tools will open. Click the Save button the developer tools window and it will save the current version of the DOM as an HTM file.

You'll have to save other resources (images, js, css, etc.) separately.

CodeThug
  • 3,054
  • 1
  • 21
  • 17
  • Thanks for the suggestion, but that's not a viable solution for this scenario. – Simon Lang Feb 10 '12 at 04:52
  • @captainclam, can you give us some more details about why this isn't a viable solution? What do you need beyond merely saving the current version of the page and its resources? What else are you looking for? – CodeThug Feb 10 '12 at 14:28