↑
Main Page
window.open
If
window.open()
is called with the name of an existing frame as the second argument, the URL is then
loaded into the frame with that name. For example, to load a page into the frame named
“topFrame”
,
the following code does the trick:
window.open(“http://www.wrox.com/”, “topFrame”);
This line of code behaves as if a user clicked a link with the
href
set to
http://www.wrox.com/
and
the
target
set to
“topFrame”
. The special frame names
_self
,
_parent
,
_top
, and
_blank
are also
valid.
If the name specified isn’t a valid frame name, then
window.open()
opens a new window with features
based on the third argument (feature string) of the method. If the third argument is missing, a new
browser window is opened as if you had clicked a link with
target
set to
_blank
. This means that the
new browser window is displayed with the exact same settings as the default browser window (tool-
bars, location, and statusbar are all visible).
When the third argument is used, it is assumed that a new window should be opened. The feature
string, which is a comma-separated list of settings, defines certain aspects of the newly created window.
The following table displays the various settings:
Setting
Values
Description
left
Number
Indicates the left coordinate of the new window.
This cannot be a negative number.*
top
Number
Indicates the top coordinate of the new window.
This cannot be a negative number.*
height
Number
Sets the height of the new window. This cannot be
a number less than 100.*
width
Number
Sets the width of the new window. This cannot be
a number less than 100.*
resizable
yes,no
Determines if the new window can be resized by
dragging on its border. The default is no.
scrollable
yes,no
Determines if the new window allows scrolling if
the content cannot be fit in the viewport. The
default is no.
toolbar
yes,no
Determines if the new window has its toolbar
showing. The default is no.
status
yes,no
Determines if the new window has its status bar
showing. The default is no.
location
yes,no
Determines if the new window has its location
(Web address) area showing. The default is no.
*These security features of the browser are discussed in greater detail in Chapter 19, “Deployment Issues.”
141
JavaScript in the Browser
08_579088 ch05.qxd 3/28/05 11:37 AM Page 141
Free JavaScript Editor
Ajax Editor
©
→