English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
open()Method to open a new browser window and load the specified file into it.
If a new window is created for the specified document, it can be opened through thefeaturesparameters to modify its appearance and behavior.
Useclose()Method to close the window.
window.open(url, name, features, replace)
window.open("https://www.oldtoolbag.com");Test and See‹/›
All browsers fully support the open() method:
Method | |||||
open() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
url | (Optional) The URL of the web page to be opened. If the URL is not set, the window.open() method will open a blank window |
name | (Optional) Specify the name or target attribute of the window. Possible values:
|
features | (Optional) A comma-separated list of items without spaces. Possible values: channelmode = yes|no| 1 | 0 Whether to display the window in theater mode. Default is no. Only IEdirectories=yes|no|1|0 Outdated Whether to add a directory button. Default is yes. Only IE fullscreen=yes|no|1|0 Whether to display the browser in full-screen mode. Default is no. The window in full-screen mode must also be in theater mode. Only IE height=pixels The height of the window. The minimum value is100 left=pixels The left position of the window. Negative values are not allowed location=yes|no|1|0 Whether to display the address field. Only for Opera menubar=yes|no|1|0 Whether to display the menu bar resizable=yes|no|1|0 Whether the window can be resized. Only for IE scrollbars=yes|no|1|0 Whether to display the scroll bar. Only for IE, Firefox and Opera status=yes|no|1|0 Whether to add a status bar titlebar=yes|no|1|0 Whether to display the title bar. It will be ignored unless the calling application is an HTML application or a trusted dialog toolbar=yes|no|1|0 Whether to display the browser toolbar. Only for IE and Firefox top=pixels Window top position. Negative values are not allowed width=pixels Window width. The minimum value is100 |
replace | (Optional) Specify whether to create a new entry or replace the current document in the history record list. Possible values:
|
Return value: | Represents the Window object of the newly created window. If the window cannot be opened, the return value is null. |
---|
Open a blank page in the new window:
window.open("", "", "width=400, height=300");Test and See‹/›
Open a new window. Use the name attribute to return the name of the new window:
var win = window.open("", "popupWindow", "width=400, height=300"); win.document.write("<p>This window&"39;s name is: " + win.name + "</p>Test and See‹/›
Open "parrot" in a new window with specified height and width:-tutorial.com":
window.open("https://www.oldtoolbag.com", "", "width=400, height=300");Test and See‹/›
Open "parrot" in a new window at the specified location:-tutorial.com":
window.open("https://www.oldtoolbag.com", "", "left=500, top=200");Test and See‹/›
Open a new window and specify its appearance:
window.open("https://www.oldtoolbag.com", _blank,), "toolbar=yes,scrollbars=yes,resizable=yes,top=200,left=500,width=400,height=300");Test and See‹/›
Open a new window and close it using the close() method:
var popupWindow; //Function to open a new window function windowOpen() { popupWindow = window.open("https://www.oldtoolbag.com", _blank"); } // Function to close the opened window function windowClose() { if (popupWindow) { popupWindow.close(); } }Test and See‹/›
Use the opener property to return a reference to the window that created the new window:
// Open a new window var win = window.open("", "popupWindow", "width=300, height=200"); //Write some content in the new window win.document.write("<p>The name of this window is: " + win.name + "</p> // Write some text in the window created by opening a new one win.opener.document.write("<h1>This is the source window!/h1});Test and See‹/›
Window (Window) Reference:close() method
Window (Window) Reference:closed property
Window (Window) Reference:opener property