document.write() Methoddocument.write() method takes a HTML content to write to the window or frame. After a page loads any document.write() method called in curent page will erase the content page, and opens a new data stream. when you press "the same window" button document.write() method will erase the page and write another content. If you press "The other window" different page will be displayed.
Here is an example.
<script language="JavaScript">
<!--
function SameW() {
var s = "<HTML><HEAD><TITLE>New document </TITLE></HEAD></HTML>"
s+="<BODY leftmargin=\"20\"><h1>This is a new document generated by <code><font
color=\"navy\">document.write()</font></code> Method</h1>"
s+="If you want to go back to previous page press back button on your browser."
s+="</BODY></HTML>"
document.write(s)
document.close()
}
//-->
</script>
<FORM>
<INPUT TYPE = "button" VALUE = "The same window" onClick = "SameW()">
</FORM>
<script language="JavaScript">
<!--
var secWindow
function openW(){
secWindow = window.open("","","status HEIGHT = 400, WIDTH=600")
}
function OtherW() {
openW()
//Make secWindow active
secWindow.focus()
var s = "<HTML><HEAD><TITLE>New document </TITLE></HEAD></HTML>"
s+="<BODY leftmargin=\"20\"><h1>This is a new document generated by <code><font
color=\"navy\">document.write()</font></code> Method which is dislpayed in new window</h1>"
s+="This is a new document generated by <code><font color=\"navy\">document.write()</font></code>
Method which is dislpayed in new window."
s+="</BODY></HTML>"
secWindow.document.write(s)
}
//-->
</script>
<FORM>
<INPUT TYPE = "button" VALUE = "The other window" onClick = "OtherW()">
</FORM>