HTML and CSS Reference
In-Depth Information
Figure 17.17 shows the result.
.
Output
FIGURE 17.17
An inline (or float-
ing) frame.
Pop-up windows are used all over the Web. They are often used to display advertise-
ments, but they can be used for all sorts of other things, as well, such as creating a sepa-
rate window to show help text in an application or to display a larger version of a graph
that's embedded in a document. You've seen how you can use the
target
attribute to
open a link in a new window, but that approach isn't flexible. You can't control the size
of the window being displayed, nor which browser interface controls are displayed.
17
Fortunately, with JavaScript you can take more control of the process of creating new
windows. You've already learned that one of the objects supported by JavaScript is
win-
dow
. It refers to the window that's executing the script. To open a new window, you use
the
open
method of the
window
object. Here's a JavaScript function that opens a window:
function popup(url) {
mywindow = window.open(url, 'name', 'height=200,width=400');
return false;
}
The function accepts the URL for the document to be displayed in the new window as an
argument. It creates a new window using the
window.open
function, and assigns that new
window to a variable named
mywindow
. (I explain why we assign the new window to a
variable in a bit.)
The three arguments to the function are the URL to be displayed in the window, the
name for the window, and a list of settings for the window. In this case, I indicate that I
want the window to be 400 pixels wide and 200 pixels tall. The name is important
because if other links target a window with the same name, either via the
window.open()
function or the
target
attribute, they'll appear in that window.


