You are here: Reference > JavaScript > client-side > HTML DOM > methods > open (window)

open method (window)

Browser support:
Creates a new window and loads the specified document into it.
In that case if a new document needs to be loaded into the current window, the open method can be used also.
If a new window is created for the specified document, its appearance and behavior can be modified by the features parameter of the open method. To communicate between the opener and the opened windows, use the opener property in the opened windows and the window object returned by the open method.
  • If you need to open a modal window, use the showModalDialog method instead, it is supported by Internet Explorer, Firefox, Google Chrome and Safari, while the 'modal' feature of the open method is only supported by Firefox.
  • If you need to open a modeless dialog, the showModelessDialog method can also be used in Internet Explorer.

Syntax:

object.open ([URL [, name [, features [, replace]]]]);
You can find the related objects in the Supported by objects section below.

Parameters:

URL
Optional. String that specifies the location of the document to load. Use the 'about:blank' value to open an empty document.
name
Optional. String that specifies the name of the new window, or specifies the target window where the document needs to be opened.
One of the following values:
_blank
The document needs to be opened into a new window. The name of the new window is an empty string initially.
_media
7
The document needs to be opened in the Media Bar. This value is no longer supported by Internet Explorer. Do not use it!
_parent
The document needs to be opened in the parent window of the current frame. If the current window has no parent, the document will be opened in the current window.
_search
7
The document needs to be opened in the Search Pane. The Search Pane is disabled in Internet Explorer from version 7. Do not use this value!
_self
The document needs to be opened in the current window.
_top
The document needs to be opened in the topmost ancestor window in the window hierarchy. If the current window has no parent, the document will be opened in the current window.
name
A string that specifies the initial name for the new window.
In Internet Explorer, the value must not contain spaces. The name of windows can be used to identify them.
When a new window needs to be opened with a specified name and a window opened by the current document already exists with the same name, then the browser uses the existing window, instead of creating a new one.
For further details, please see the page for the name property.
features
Optional. String that specifies a comma-separated list of options.
Each option is a name, value pair, delimited by an equals sign. Features have effect only when a new window is created for the opened document. If no features are specified, the new window has the same settings (width, height, toolbar...) as the opener window.
The following features are supported:
left = number
Where the number is an integer that specifies the left position of the new window relative to the left side of the screen, in pixels. Negative values are not allowed.
top = number
Where the number is an integer that specifies the top position of the new window relative to the top side of the screen, in pixels. Negative values are not allowed.
height = number
Where the number is an integer that specifies the height of the new window's client area, in pixels. Minimum value is 100.
width = number
Where the number is an integer that specifies the width of the new window's client area, in pixels. Minimum value is 100.
innerHeight = number
Same as height.
innerWidth = number
Same as width.
outerHeight = number
Specifies the height of the new window, in pixels. Minimum value is 100.
outerWidth = number
Specifies the width of the new window, in pixels.
directories = yes|no
7
Specifies whether the Links bar (Internet Explorer), and the Bookmarks Toolbar (Firefox) are displayed in the new window. This feature is not supported in Internet Explorer from version 7.
personalbar = yes|no
Same as directories.
location = yes|no
Specifies whether the Location bar (Firefox, Google Chrome and Safari) and the Address bar (Internet Explorer and Opera) are displayed in the new window.
menubar = yes|no
Specifies whether the menu bar is displayed in the new window.
scrollbars = yes|no
Specifies whether displaying scrollbars are allowed for the new window.
status = yes|no
Specifies whether the new window has a status bar.
titlebar = yes|no
Specifies whether the new window has a title bar. This feature requires the UniversalBrowserWrite privilege in Firefox, and ignored in Internet Explorer unless the calling application is an HTML Application or a trusted dialog box.
toolbar = yes|no
Specifies whether the Navigation bar (Firefox, Opera, Google Chrome and Safari) and the Command bar (Internet Explorer) are displayed in the new window.
channelmode = yes|no
Specifies whether the new window is opened in channel mode.
fullscreen = yes|no
Specifies whether the new window is opened in full-screen mode.
close = yes|no
Specifies whether the close button is displayed in the system menu bar of the new window. The close button can only be removed from dialog windows (dialog=yes). This feature requires the UniversalBrowserWrite privilege.
minimizable = yes|no
Specifies whether the minimize button is displayed in the system menu bar of the new window. Has effect only on dialog windows (dialog=yes).
resizable = yes|no
Specifies whether the new window is resizable.
alwaysRaised = yes|no
Specifies whether the new window will always be displayed on top of other Firefox browser windows.
alwaysLowered = yes|no
Specifies whether the new window will always be displayed on lower level than its parent window, except when the parent window is minimized.
z-lock = yes|no
Same as alwaysLowered.
chrome = yes|no
Specifies whether the new window is opened without interface elements and context menu. This feature requires the UniversalBrowserWrite privilege.
dependent = yes|no
Specifies whether the new window is dependent of its parent window.
dialog = yes|no
Specifies whether the restore, minimize and maximize buttons are displayed in the system menu bar of the new window.
modal = yes|no
Specifies whether to display the window in modal mode (like alert window). This feature requires the UniversalBrowserWrite privilege in Firefox.
replace
Optional. Boolean that specifies whether the URL of the opened document replaces the current entry in the history list or adds a new entry into it. This parameter has effect only if the document is opened in the current window.
One of the following values:
false
URL creates a new entry in the history list.
true
URL replaces the URL of the current document in the history list.

Return value:

Returns the window object that contains the specified document.

Example HTML code 1:

This example opens an empty document and writes some HTML formatted content into it:
<head>
    <script type="text/javascript">
        function OpenWindow () {
            var childWin = window.open ("about:blank", "MyWindow", "height=150,width=200");
            childWin.document.body.innerHTML = "<span style='color:red'>Hello World!</span>";
        }
    </script>
</head>
<body>
    <button onclick="OpenWindow ();">Open a new window</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content