Reading time: 2 minutes
Hi, we continue with the JavaScript window object.
In this tutorial, continuing from the previous Creating JavaScript Windows (Window Object) 2/3, what we want to demonstrate in the functionality is the following:
<html> <head> <script> function openNewWindow(windowName) { // open a new window with the name passed as a parameter // no URL is specified myWindow = window.open("example02ObjWindows.html", windowName, "width=500,height=400,status=yes,toolbar=yes,menubar=yes"); // Open the document's stream for writing // myWindow.document.open(); // Create the document // myWindow.document.write("<html><head><title>Example of creating windows for DevCodeLight"); // myWindow.document.write("</title></head><body>"); // myWindow.document.write("<h1>Creating windows with content in the document</h1>"); // myWindow.document.write("<p> </p>"); // myWindow.document.write("<p>The content is dynamic, and it is an example for <a href='https://devcodelight.com/'>devcodelight.com</a></p>"); // myWindow.document.write("<input type='button' value='Close window' onclick='window.close();'/>"); // myWindow.document.write("</body></html>"); // close the document's stream // myWindow.document.close(); } // --> </script> </head> <body> <form><input type=button value="Open window" onClick="openNewWindow('new')"></form> </body> </html>
In this last example, what we’re doing is commenting out all the code and leaving only this line:
myWindow = window.open("example02ObjWindows.html", windowName, "width=500,height=400,status=yes,toolbar=yes,menubar=yes");
What we’re saying is to open the file “example02ObjWindows.html”; it opens it and shows us the window created in that file, displaying the content of that HTML. When we click “Open window” on the corresponding button, it displays the content in “example02ObjWindows.html”; and then, if we click “Close”, it closes everything and we go back to the main page.
That’s it. See you in the next one! :slightly_smiling_face: