Mega Code Archive

 
Categories / JavaScript DHTML / Window Browser
 

Communicating with a New Window

<html> <head> <title>Recipe 6.6</title> <script type="text/javascript"> var newWindow; function makeNewWindow() {     if (!newWindow || newWindow.closed) {         newWindow = window.open("","sub","status,height=200,width=300");         setTimeout("writeToWindow()", 50);     } else if (newWindow.focus) {         newWindow.focus();     } } function writeToWindow() {     var newContent = "<html><head><title>Secondary  Window</title></head>";     newContent += "<body><h1>This is a script-created window.</h1>";     newContent += "</body></html>";     newWindow.document.write(newContent);     newWindow.document.close(); } </script> </head> <body> <h1>Communicating with a New Window</h1> <hr />  <form> <input type="button" value="Create New Window" onclick="makeNewWindow();" /> </form> </body> </html>