These days, popup windows are generally frowned upon; however, they can be useful in some cases. We'll look at a couple of examples, but first, let's see how to open a new window.
var newWin = window.open(URL, name, features, replace);
All four parameters are options:
URL- the URL of the page to load. If it is left blank, a blank window is open and can be written to with
targetattribute of the window. This can be used to reuse an existing window if it is open.
features- a comma-delimited list of window features. Some of the most common are:
height- the height of the window
width- the width of the window
left- the left position of the window
top- the top position of the window
location- whether or not to include the location bar
menubar- whether or not to include the menubar
resizable- whether or not the window should be resizable
scrollbars- whether or not to include scrollbars
status- whether or not to include the status bar
toolbar- whether or not to include the toolbar
replace- true or false. If set to true, the new page replaces the current page (if there is one) in the browser window's history.
top features should be set in pixels.
toolbar features are boolean values: "true" or "false", "yes" or "no", or "1" or "0" will work.
The HTML5 specification advises browsers to ignore the
features arguments completely, and some modern browsers do choose to ignore all but the size and positioning features.
The example below shows how to open a new window:
Things to notice:
eulaa global variable so that we can access the window object from within multiple functions.
openWin()function, we call
eula.focus();after opening the window. That's to bring the window to the foreground if it's already been opened.
confirmEulacheckbox has been checked before the EULA window has been opened (i.e., before a
windowobject has been assigned to the
eulavariable). In this case, we scold the user and pop up the EULA window.
confirmEulacheckbox has been checked and the EULA window is left open, in which case we close the EULA window via the
confirmEulacheckbox has been unchecked, we pop the EULA window back open.