Window open()Method

Window 对象参考手册Window Object

Definition and Usage

The open() method is used to open a new browser window or find a named window.

Syntax

window.open(URL,name,specs,replace)

Parameters Description
URL Optional. The URL of the page to open. If no URL is specified, a new blank window is opened.
name Optional. Specifies the target attribute or the name of the window. Supports the following values:
  • _blank - URL loads into a new window. This is the default.
  • _parent - URL loads into the parent frame.
  • _self - URL replaces the current page.
  • _top - URL replaces any loadable frameset.
  • namename - Window name.
specs Optional. A comma-separated list of items. Supports the following values:

channelmode=yes|no|1|0 Whether to display the window in theater mode. Default is no. Internet Explorer only.
directories=yes|no|1|0 Whether to add a directory button. Default is yes. Internet Explorer only.
fullscreen=yes|no|1|0 Whether the browser displays full-screen mode. Default is no. A window in full-screen mode must also be in theater mode. Internet Explorer only.
height=pixels The height of the window. Minimum value is 100.
left=pixels The left position of the window.
location=yes|no|1|0 Whether to display the address field. Default is yes.
menubar=yes|no|1|0 Whether to display the menu bar. Default is yes.
resizable=yes|no|1|0 Whether the window can be resized. Default is yes.
scrollbars=yes|no|1|0 Whether to display scroll bars. Default is yes.
status=yes|no|1|0 Whether to add a status bar. Default is yes.
titlebar=yes|no|1|0 Whether to display the title bar. Ignored unless calling an HTML application or a trusted dialog. Default is yes.
toolbar=yes|no|1|0 Whether to display the browser toolbar. Default is yes.
top=pixels The top position of the window. Internet Explorer only.
width=pixels The width of the window. Minimum value is 100.

replace Optional. Specifies whether the URL loaded into the window creates a new entry in the window's browsing history or replaces the current entry in the browsing history. Supports the following values:
  • true - The URL replaces the current entry in the browsing history.
  • false - The URL creates a new entry in the browsing history.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the open() method.


Examples

Example 1

Open www.example.com in a new browser window:

function open_win() { window.open("https://www.example.com"); }

Try it Yourself »

Example 2

The following example opens a blank window in a new browser:

function openWin(){ myWindow=window.open('','','width=200,height=100'); myWindow.document.write("<p>This is 'My Window'</p>"); myWindow.focus(); }

Try it Yourself »


实例s

More Examples

Open a new window and control its appearance

Open multiple windows with one click

Open a page in a new window/tab


Window 对象 参考手册Window Object Other Extensions