Opening a new window with JavaScript

The following code is placed immediately before the closing </body> tag. The script works by manipulating the DOM, so placing it at the end of the file allows the DOM to complete before the script can run:


function newWindow(){"class-01-js-window.html", "exampleWin", "width=650,height=500")

var openWin = document.getElementById("open");
openWin.onclick = newWindow;


The open.window method has 3 parameters:

  1. The URL of the page to be loaded into the window. class-01-js-window.html in the example above.
  2. The name of the window. exampleWin in the example above
  3. The list of properties. In the example above, only the width and height properties are used but there are others.

The window can be activated in a number of ways but having the user click an element is useful. Click the "button" to see what happens.

Open a new window