prof_x
02-02-2005, 06: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):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<style type="text/css" id="style">
.red {color:#FF0000}
</style>
<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");
win.document.write(unescape(doc));
win.document.close();
parent.win = self;
}
</script>
</head>
<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>!
</body>
</html>
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.
Help?
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):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<style type="text/css" id="style">
.red {color:#FF0000}
</style>
<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");
win.document.write(unescape(doc));
win.document.close();
parent.win = self;
}
</script>
</head>
<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>!
</body>
</html>
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.
Help?