Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Window open() method

Window open() method

Window Object Reference 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. Supported values:
  • _blank - The URL is loaded into a new window. This is the default
  • _parent - The URL is loaded into the parent frame
  • _self - The URL replaces the current page
  • _top - The URL replaces any loadable frameset
  • name - Window name
  • | | specs | Optional. A comma-separated list of items. Supported values:
       
    
    channelmode=yes\|no\|1\|0 Whether to display the window in theater mode. Default is no. IE only   directories=yes\|no\|1\|0 Whether to add a directory button. Default is yes. IE only   fullscreen=yes\|no\|1\|0 Whether the browser displays in fullscreen mode. Default is no. In fullscreen mode the window must also be in theater mode. IE 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 is resizable. Default is yes   scrollbars=yes\|no\|1\|0 Whether to display scrollbars. 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 an HTML application or a trusted dialog is called. 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. IE only   width=pixels The width of the window. Minimum value is 100 | channelmode=yes\|no\|1\|0 | Whether to display the window in theater mode. Default is no. IE only | directories=yes\|no\|1\|0 | Whether to add a directory button. Default is yes. IE only | fullscreen=yes\|no\|1\|0 | Whether the browser displays in fullscreen mode. Default is no. In fullscreen mode the window must also be in theater mode. IE 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 is resizable. Default is yes | scrollbars=yes\|no\|1\|0 | Whether to display scrollbars. 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 an HTML application or a trusted dialog is called. 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. IE only | width=pixels | The width of the window. Minimum value is 100 | | channelmode=yes\|no\|1\|0 | Whether to display the window in theater mode. Default is no. IE only | | directories=yes\|no\|1\|0 | Whether to add a directory button. Default is yes. IE only | | fullscreen=yes\|no\|1\|0 | Whether the browser displays in fullscreen mode. Default is no. In fullscreen mode the window must also be in theater mode. IE 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 is resizable. Default is yes | | scrollbars=yes\|no\|1\|0 | Whether to display scrollbars. 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 an HTML application or a trusted dialog is called. 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. IE 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 browsing history or replaces the current entry in the browsing history. Supported 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.


    Example

    Example 1

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

    function

    open_win

    (

    )

    {

    window

    .

    open

    (

    "

    https://www.runoob.com

    "

    )

    ;

    }

    Try it »

    Example 2

    The example below opens a blank window page in a new browser:

    function

    openWin

    (

    )

    {

    myWindow

    =

    window

    .

    open

    (

    '

    '

    ,

    '

    '

    ,

    '

    width=200,height=100

    '

    )

    ;

    myWindow

    .

    document

    .

    write

    (

    "

    This is 'my window'

    "

    )

    ;

    myWindow

    .

    focus

    (

    )

    ;

    }

    Try it »


    More examples

    Open a new window and control its appearance

    Open multiple windows with a single click

    Open a page in a new window/tab


    Window Object Reference Window Object

    Source: Runoob Tutorial · Original modified: 2021-03-11T12:11:26 · This copy is for personal offline learning only; public distribution is prohibited.