ventana abierta()
Ejemplo 1
Abra "www.w3schools.com" en una nueva pestaña del navegador:
window.open("https://www.w3schools.com");
Más ejemplos a continuación.
Definición y uso
El open()
método abre una nueva ventana del navegador, o una nueva pestaña, según la configuración de su navegador y los valores de los parámetros.
Ver también:
Sintaxis
window.open(URL, name, specs, replace)
Parámetros
Parameter | Description | ||||||||||||||||||||||||
URL | Optional. The URL of the page to open. If no URL is specified, a new blank window/tab is opened |
||||||||||||||||||||||||
name | Optional. The target attribute or the name of the window. The following values are supported: | ||||||||||||||||||||||||
|
|||||||||||||||||||||||||
specs | Optional. A comma-separated list of items, no whitespaces. The following values are supported: | ||||||||||||||||||||||||
| |||||||||||||||||||||||||
replace |
DeprecatedSpecifies whether the URL creates a new entry or replaces the current entry in the history list. The following values are supported:
WarningChrome throws an exception when using this parameter. Source: . |
Valor devuelto
Una referencia a la nueva ventana, o nulo si la llamada falló. |
Más ejemplos
Abra una página about:blank en una nueva ventana/pestaña:
var myWindow = window.open("", "", "width=200,height=100");
Abra una nueva ventana llamada "MsgWindow" y escriba algo de texto en ella:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
Reemplace la ventana actual con una nueva ventana:
var myWindow = window.open("", "_self");
myWindow.document.write("<p>I replaced the current window.</p>");
Abre una nueva ventana y controla su apariencia:
window.open("https://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
Abre varias pestañas:
window.open("http://www.google.com/");
window.open("https://www.w3schools.com/");
Abre una nueva ventana. Use close() para cerrar la nueva ventana:
function openWin() {
myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window
}
function closeWin() {
myWindow.close(); // Closes the new window
}
Abre una nueva ventana. Utilice la propiedad de nombre para devolver el nombre de la nueva ventana:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
Usando la propiedad opener para devolver una referencia a la ventana que creó la nueva ventana:
var myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window
myWindow.document.write("<p>This is 'myWindow'</p>"); // Text in the new window
myWindow.opener.document.write("<p>This is the source window!</p>"); // Text in the window that created the new window
Compatibilidad con navegador
open()
es compatible con todos los navegadores:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |