RobG <rg***@iinet.net.au> wrote:
joe wrote: I have a Javascript page which needs to be dynamically changed depending on user
input. The whole page is written on document.write() output.
That does not seem like a good idea. You should just modify the bits
that need to change, not re-write the entire page.
I am still new to Javascript and run into problems with page reload. When user
presses a button on my page most functions should clear the page and repaint it
using my wholepage() function. After a couple of repaint the page goes into some
error. Am I supposed to clear the div's in the page or wot?
Calling document.write() after the page has finished loading will result
in a call to document.open(), which will clear the entire page content.
In some browsers, all script other than the one currently executing are
removed from memory immediately, in others they persist until the new
page is written but then are gone.
"clear the div's" is meaningless.
I have a full sample here (below).
The page shows a "Hello" and "Press here". When user clicks the button at first
everything is OK. On second click IE shows "Error on page"
<SCRIPT LANGUAGE="JavaScript">
function mybutton(nap) {
window.alert("You pressed "+nap.toString());
wholepage();
return true; }
function wholepage() {
document.write("<html> <head>");
document.write("<title>Test page</title>");
document.write('<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">');
document.write('<body bgcolor="#CCCCCC">');
document.write('<div id="Layer1" style="position:absolute; width:600px;
height:230px; left: 10px; top: 50px; z-index:1">');
document.write('<table width="590" border="1" height="172">');
document.write("<tr>");
document.write('<td height="25" width="404" bgcolor="#999999" colspan="2">');
document.write("Hello");
document.write('<input type="BUTTON" name="submit" value="Press here"
onClick="mybutton(1);">');
document.write("</td></tr>");
document.write("</table> </div> ");
document.write("</body></HEAD></html>");
document.close();
return true;}
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
wholepage();
</SCRIPT>