Latest web development tutorials

Window open () method

Window Object Reference Window object

Definition and Usage

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

grammar

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

parameter Explanation
URL Optional. Open URL specified page. If you do not specify a URL, open a new blank window
name Optional. Specifies the name of the target attribute or window. It supports the following values:
  • _blank - URL is loaded into a new window. This is the default
  • _parent - URL is loaded into the parent frame
  • _self - URL replaces the current page
  • _top - URL replaces any framesets loadable
  • name -the name of the window
specs Optional. A comma-separated list of items. It supports the following values:

channelmode = yes | no | 1 | 0 Do you want to display the window in theater mode. The default is none. IE only
directories = yes | no | 1 | 0 Whether to add directory buttons. The default is yes. IE only
fullscreen = yes | no | 1 | 0 Whether the browser displays full-screen mode. The default is none. In full-screen mode the window, must also be in theater mode. IE only
height = pixels Height of the window. Min. Value of 100
left = pixels The left position of the window
location = yes | no | 1 | 0 Whether to display the address field. The default is yes
menubar = yes | no | 1 | 0 Whether to display the menu bar. The default is yes
resizable = yes | no | 1 | 0 Whether to adjust the window size. The default is yes
scrollbars = yes | no | 1 | 0 Whether to display the scroll bar. The default is yes
status = yes | no | 1 | 0 Do you want to add a status bar. The default is yes
titlebar = yes | no | 1 | 0 Whether to display the title bar. Is ignored unless you call the HTML application or a trusted dialog box. The default is yes
toolbar = yes | no | 1 | 0 Whether to display the browser toolbar. The default is yes
top = pixels Location top of the window. IE only
width = pixels Width of the window. Min. Value of 100

replace Optional.Specifies specifies the URL is loaded into the window to create a new entry in the browsing history window, or replaces the current entry in the browsing history. It supports the following values:
  • true - URL replaces the current entry in the browsing history.
  • false - URL to create a new entry in the browsing history.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support open () method


Examples s

Example 1

Opens in a new browser window www.w3big.com:

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function open_win () {
window.open ( "http://www.w3big.com");
}
</ Script>
</ Head>
<Body>

<Form>
<Input type = "button" value = "open window" onclick = "open_win ()">
</ Form>

</ Body>
</ Html>

try it"

Example 2

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

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

try it"


Examples s

More examples

A new window opens, and control their appearance


Window Object Reference Window object