View Full Version : When saving dynamically generated documents, the parent document is the one saved.

02-02-2005, 07:23 PM
Hi there

I am developing some tools for my department and I require some DHTML in them. The problem here is that when I create a document dinamically, i want my users to be able to save their dinamically generated documents, and this is not working neither on IE nor Mozilla (need the script to work on both browsers). If I click on the Save Page As option on the File Menu, the -parent- window document is the one that gets saved. But, if you view the source of the new document, you get the right content, and you can save the new content from here (-Save Page As- option from the -File- menu). Any idea around why this is happening and how to solve this problem? (Another variable in this issue is that I am using Spanish, but using the right charset solves it.)

Here is an example code of this behavior (i tried to write one as small as possible):

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="style">
.red {color:#FF0000}
<script language="JavaScript" type="text/javascript">
function render()
var doc = "<html lang=\"es\" xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"es\">\n<head>\n";
doc += "<META HTTP-EQUIV=\"Content-Language\" Content=\"es\" />\n";
doc += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"; //charset=iso-8859-1
doc += "<title></title>\n<style type=\"text/css\">\n";
doc += document.getElementById("style").innerHTML;
doc += "</style>\n<body id='body'>\n" + escape(document.getElementById("body").innerHTML);
doc += "</body>\n</html>";
var win = window.open("","","width=800;height=600,menubar,scrollbars,resizable");
parent.win = self;

<body id="body">
<span onclick="this.innerHTML='SOMETHING JUST CHANGED!'">This text is in spanish</span>: ¡Visita México este año <a href="#" onclick="render()" title="Click me!">2005</a>!

If you click on the text "This text is in spanish", you get new text. Try it. Now, click on "2005". You´ll get the new document. Now save it and open it in a browser: -you got the parent document-. Now view the source of the new document: -you get the new content-.

I´ve been researching about this issue for a pair of weeks now with no success at all.


02-02-2005, 07:27 PM
The browser is saving the document from the server/cache. It will not save the changes made to it. You most likely need a server side code to create the page and have them download it.


02-02-2005, 07:41 PM
Thanks Eric, but...

... i do not have the option of a server-side generated document, reason for which i am working entirely on a client-side solution.

Are you saying that there is -no way- to save client-side generated documents as the browser will always save which ever document is in the server/cache (that is, the parent document)?