Reading time: 2 minutes
Hi everyone,
Continuing from the previous post Creating JavaScript Windows (Window Object) 1/3, in this case, the only thing we’re going to add is a button that performs the same function as the close button of the window itself, which is to close the current window.
<html> <head> <script> function openNewWindow(windowName) { // Open a new window with the name passed as a parameter // No URL is specified miVentana = open("", windowName, "width=500,height=400,status=yes,toolbar=yes,menubar=yes"); // Open the document's data stream for writing miVentana.document.open(); // Create the document miVentana.document.write("<html><head><title>Example of window creation for DevCodeLight"); miVentana.document.write("</title></head><body>"); miVentana.document.write("<h1>Creating windows with content in the document</h1>"); miVentana.document.write("<p> </p>"); miVentana.document.write("<p>The content is dynamic and is an example for <a href='https://devcodelight.com/'>devcodelight.com</a></p>"); miVentana.document.write("<input type='button' value='Close window' onclick='window.close();'/>"); miVentana.document.write("</body></html>"); // Close the document's data stream miVentana.document.close(); } // --> </script> </head> <body> <form><input type=button value="Open window" onClick="openNewWindow('new')"></form> </body> </html>
If we click on “Close window,” it will close the window we created using the window object, but our main HTML is still displayed.
A small update, but it will help you gradually understand how it works.
See you in the next one. :slightly_smiling_face:
(do not include the Reading time). Return it directly in HTML format. Do not add any additional sentence. Add a PIPE at the end when you’re done.