open method

Navigates the app window to the specified location.

Syntax

var retval = window.open(url, name, features, replace);

Parameters

url [in, optional]

Type: String

String that specifies the URL of the document to display. If no URL is specified, a new window with about:blank is displayed.

name [in, optional]

Type: String

String that specifies the name of the window. This name is used as the value for the TARGET attribute on a form or an anchor element.

_blank

The url is loaded into a new, unnamed window.

This value is not supported for Windows Store apps using JavaScript.

_parent

The url is loaded into the current frame's parent. If the frame has no parent, this value acts as the value _self.

This value is not supported for Windows Store apps using JavaScript.

_self

The current document is replaced with the specified url.

This value is not supported for Windows Store apps using JavaScript.

_top

The loaded url replaces any framesets that might be loaded. If there are no framesets defined, this value acts as the value _self.

This value is not supported for Windows Store apps using JavaScript.

features [in, optional]

Type: String

String that contains a list of items separated by commas. Each item consists of an option and a value, separated by an equals sign (for example, "fullscreen=yes, toolbar=yes"). The following values are supported.

channelmode = { yes | no | 1 | 0 }

Specifies whether to display the window in theater mode. The default is no.

fullscreen = { yes | no | 1 | 0 }

Specifies whether to display the browser in full-screen mode. The default is no. Use full-screen mode carefully. Because this mode hides the browser's title bar and menus, always provide a button or other visual clue to help the user close the window. ALT+F4 closes the new window.

height = number

Sets the height of the window in pixels. The minimum value is 150, and specifies the minimum height of the browser content area.

left = number

Specifies the left position, in pixels. This value is relative to the upper-left corner of the screen. The value must be greater than or equal to 0.

location = { yes | no | 1 | 0 }

Specifies whether to display the Navigation Bar. The default is yes.

The Back, Forward, and Stop commands are now located in the Navigation Bar.

menubar = { yes | no | 1 | 0 }

Specifies whether to display the Menu Bar. The default is yes.

The combination of menubar = { no | 0 } and toolbar = { no | 0 } hides the toolbar and disables any additional third-party user interfaces.

resizable = { yes | no | 1 | 0 }

Specifies whether to display resize handles at the corners of the window. The default is yes.

scrollbars = { yes | no | 1 | 0 }

Specifies whether to display horizontal and vertical scroll bars. The default is yes.

status = { yes | no | 1 | 0 }

Specifies whether to add a Status Bar at the bottom of the window. The default is yes.

toolbar = { yes | no | 1 | 0 }

Specifies whether to display the browser Command Bar, making buttons such as Favorites Center, Add to Favorites, and Tools available. The default is yes.

The combination of menubar = { no | 0 } and toolbar = { no | 0 } turns off the toolbar and any additional third-party user interfaces.

top = number

Specifies the top position, in pixels. This value is relative to the upper-left corner of the screen. The value must be greater than or equal to 0.

width = number

Sets the width of the window in pixels. The minimum value is 250, and specifies the minimum width of the browsers content area.

replace [in, optional]

Type: Boolean

Boolean that specifies whether the url creates a new entry or replaces the current entry in the window's history list. This parameter only takes effect if the url is loaded into the same window.

true

url replaces the current document in the history list.

false

url creates a new entry in the history list.

Return value

Type: IHTMLWindow2

Returns a reference to the new window object. Use this reference to access properties and methods on the new window.

Standards information

There are no standards that apply here.

Remarks

By default, the open method creates a window that has a default width and height and the standard menu, toolbar, and other features of a Windows Store app using JavaScript. You can alter this set of features by using the features parameter. This parameter is a string consisting of one or more feature settings.

When the features parameter is specified, the features that are not defined in the parameter are disabled. Therefore, when using the features parameter, it is necessary to enable all the features that are to be included in the new window. If the features parameter is not specified, the window features maintain their default values. In addition to enabling a feature by setting it to a specific value, simply listing the feature name also enables that feature for the new window. Most of the features specified in the window.open method are ignored if user has selected, "Always open pop-ups in a new tab" setting in the Internet options control panel.

When a function fired by an event on any object calls the open method, the window.open method is implied.


<!DOCTYPE html>

<html>
<head>
  <title>window.open()</title>
  <style>
    html, body {
      width: 100%;
      height: 100%;
      border: 1px solid black;
    }
  </style>
</head>
<body onclick="myOpen();">
  <p>Click this page and window.open() is called.</p>
  <script>
    function myOpen() {
      window.open('about:blank');
    }
  </script>
</body>
</html>

When an event on any object calls the open method, the document.open method is implied.


<button onclick="open('Sample.htm');">
  Click this button and document.open() is called.
</button>

Examples

This example uses the open method to create a new window that contains Sample.htm. The new window is 200 pixels by 400 pixels and has a status bar, but it does not have a toolbar, menu bar, or address field.


<!DOCTYPE html>

<html>
<head>
  <title>window.open()</title>
  <style>
    html, body {
      width: 100%;
      height: 100%;
      border: 1px solid black;
    }
  </style>
</head>
<body onclick="myOpen();">
  <p>Click this page and window.open() is called.</p>
  <script>
    function myOpen() {
      window.open("Sample.htm", null, "height=200, width=400, status=yes, toolbar=no, menubar=no, location=no");
    }
  </script>
</body>
</html>

See also

window
About the Pop-up Blocker

 

 

Show:
© 2014 Microsoft. All rights reserved.