English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Window open() Method

Объект окна JavaScript

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.

Syntax:

window.open(url, name, features, replace)
window.open("https://ru.oldtoolbag.com");
Тестировать, посмотреть‹/›

Browser compatibility

All browsers fully support the open() method:

Method
open()YesYesYesYesYes

Parameter values

ParametersDescription
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.
Возможные значения:
  • _blank - URL is loaded into a new window (default)

  • _parent - URL is loaded into the parent frame

  • _self - URL replaces the current page

  • _top - URL replaces all frames that may be loaded

  • name -Window name

features(Optional)A list of items separated by commas, without spaces.
Возможные значения:
channelmode = yes|no| 1 | 0 Whether to display the window in theater mode. The default is no. Only for IE
directories=yes|no|1|0  Outdated Whether to add a directory button. The default is yes. Only for IE
fullscreen=yes|no|1|0  Whether to display the browser in full-screen mode. The default is no. In full-screen mode, the window must also be in theater mode. Only for IE
height=pixels  The height of the window. The minimum value is 100
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 scroll bars. 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 is ignored unless the calling application is an HTML application or a trusted dialog.
toolbar=yes|no|1|0 - Показывать или нет браузерную панель инструментов. Доступно только в IE и Firefox
top=pixels - Верхнее положение окна. Запрещены отрицательные значения
width=pixels - Ширина окна. Минимальное значение 100
replace(Опционально) Указывает URL для создания нового элемента или замены текущего документа в списке истории URL.
Возможные значения:
  • true - Заменяет текущий документ в списке истории URL

  • false - Создает новый элемент в списке истории URL

Технические детали

Возвратное значение:Это объект Window нового созданного окна. Если не удается открыть окно, возвращается значение null.

Более примеров

Открывает пустую страницу в новом окне:

window.open("", "", "width=400, height=300");
Тестировать, посмотреть‹/›

Открывает новое окно. Использует атрибут name для возвращения имени нового окна:

var win = window.open("", "popupWindow", "width=400, height=300");
win.document.write("<p>This window's name is: " + win.name + "</p>");
Тестировать, посмотреть‹/›

Открывает "parrot-tutorial.com" в окне с указанными шириной и высотой:

window.open("https://ru.oldtoolbag.com", "", "width=400, height=300");
Тестировать, посмотреть‹/›

Открывает "parrot-tutorial.com" в окне на указанном месте:

window.open("https://ru.oldtoolbag.com", "", "left=500, top=200");
Тестировать, посмотреть‹/›

Открывает новое окно и определяет его外观:

window.open("https://ru.oldtoolbag.com", "_blank", 
"toolbar=yes,scrollbars=yes,resizable=yes,top=200,left=500,width=400,height=300");
Тестировать, посмотреть‹/›

Открывает новое окно и закрывает его с помощью метода close():

var popupWindow;
//Функция для открытия нового окна
function windowOpen() {
  popupWindow = window.open("https://ru.oldtoolbag.com", "_blank");
}
// Функция для закрытия открытого окна
function windowClose() {
  if (popupWindow) {
 popupWindow.close();
  }
}
Тестировать, посмотреть‹/›

Использовать свойства opener для возврата ссылки на окно, созданное при открытии нового окна:

// Открывать новое окно
var win = window.open("", "popupWindow", "width=300, height=200");
// Записать в новое окно
// Записать в новое окно некоторые содержимое
// Записать некоторый текст в окно, созданное при открытии нового окна
win.opener.document.write("<h1>Это исходное окно!</h1>");
Тестировать, посмотреть‹/›

См. также

Справка по окну (Window):Метод close()

Справка по окну (Window):Свойство closed

Справка по окну (Window):Свойство opener

Объект окна JavaScript