DekGenius.com
Team LiB   Previous Section   Next Section
Window.open( ) open a new browser window or locate a named window

Availability

JavaScript 1.0; enhanced in JavaScript 1.1

Synopsis

window.open(url, name, features, replace)

Arguments

url

An optional string that specifies the URL to be displayed in the new window. If this argument is omitted, or if the empty string is specified, the new window does not display a document.

name

An optional string of alphanumeric and underscore characters that specifies a name for the new window. This name can be used as the value of the target attribute of <a> and <form> HTML tags. If this argument names a window that already exists, the open( ) method does not create a new window, but simply returns a reference to the named window. In this case, the features argument is ignored.

features

A string that specifies which features of a standard browser window are to appear in the new window. The format of this string is specified in the "Window Features" section. This argument is optional; if it is not specified, the new window has all the standard features.

replace

An optional boolean argument that specifies whether the URL loaded into the new page should create a new entry in the window's browsing history or replace the current entry in the browsing history. If this argument is true, no new history entry is created. This argument was added in JavaScript 1.1. Note that it doesn't make much sense to use this argument for newly created windows; it is intended for use when changing the contents of an existing window.

Returns

A reference to a Window object, which may be a newly created or an already existing one, depending on the name argument.

Description

The open( ) method looks up an existing window or opens a new browser window. If the name argument specifies the name of an existing window, a reference to that window is returned. The returned window displays the URL specified by url, but the features argument is ignored. This is the only way in JavaScript to obtain a reference to a window which is known only by name.

If the name argument is not specified, or if no window with that name already exists, the open( ) method creates a new browser window. The created window displays the URL specified by url and has the name specified by name and the size and controls specified by features (the format of this argument is described in the next section). If url is the empty string, open( ) opens a blank window.

The name argument specifies a name for the new window. This name may contain only alphanumeric characters and the underscore character. It may be used as the value of the target attribute of an <a> or <form> tag in HTML to force documents to be displayed in the window.

In JavaScript 1.1, when you use Window.open( ) to load a new document into a named window, you can pass the replace argument to specify whether the new document has its own entry in the window's browsing history or whether it replaces the history entry of the current document. If replace is true, the new document replaces the old. If this argument is false or is not specified, the new document has its own entry in the Window's browsing history. This argument provides functionality much like that of the Location.replace( ) method.

Don't confuse Window.open( ) with Document.open( ) -- the two methods perform very different functions. For clarity in your code, you may want to use Window.open( ) instead of open( ). In event handlers defined as HTML attributes, open( ) is usually interpreted as Document.open( ), so in this case, you must use Window.open( ).

Window Features

The features argument is a comma-separated list of features that will appear in the window. If this optional argument is empty or not specified, all features are present in the window. On the other hand, if features specifies any one feature, any features that do not appear in the list do not appear in the window. The string should not contain any spaces or other whitespace. Each element in the list has the format:

feature[=value] 

For most features, the value is yes or no. For these features, the equals sign and the value may be omitted -- if the feature appears, yes is assumed, and if it doesn't, no is assumed. For the width and height features, value is required and must specify a size in pixels.

The available features and their meanings are:

channelmode

Specifies whether the window should appear in channel mode. IE 4 only.

dependent

If set to "no", specifies that the new window should not be a dependent child of the current window. Netscape 4 only.

directories

Directory buttons, such as "What's New" and "What's Cool". Netscape only.

fullscreen

Specifies whether the window should appear in full-screen mode. IE 4 only.

height

Specifies the height, in pixels, of the window's document display area.

innerHeight

Specifies the height, in pixels, of the window's document display area. Netscape 4 only.

innerWidth

Specifies the width, in pixels, of the window's document display area. Netscape 4 only.

left

The X-coordinate, in pixels, of the window. IE 4 only. In Netscape, use screenX.

location

The input field for entering URLs directly into the browser.

menubar

The menu bar.

outerHeight

Specifies the total height, in pixels, of the window. Netscape 4 only.

innerWidth

Specifies the total width, in pixels, of the window. Netscape 4 only.

resizable

If this feature is not present or is set to no, the window does not have resize handles around its border. (Depending on the platform, the user may still have ways to resize the window.) Note that a common bug is to misspell this feature as "resizeable," with an extra "e."

screenX

The X-coordinate, in pixels, of the window. Netscape 4 only. Use left in IE 4.

screenY

The Y-coordinate, in pixels, of the window. Netscape 4 only. Use top in IE 4.

scrollbars

Enables horizontal and vertical scrollbars when they are necessary.

status

The status line.

toolbar

The browser toolbar, with Back and Forward buttons, etc.

top

The Y-coordinate, in pixels, of the window. IE 4 only. Use screenY in Netscape.

width

Specifies the width, in pixels, of the window's document display area.

See Also

Location.replace( ), Window.close( ), the closed and opener properties of Window

    Team LiB   Previous Section   Next Section