Finestra aperta()
Esempio 1
Apri "www.w3schools.com" in una nuova scheda del browser:
window.open("https://www.w3schools.com");
Altri esempi di seguito.
Definizione e utilizzo
Il open()
metodo apre una nuova finestra del browser o una nuova scheda, a seconda delle impostazioni del browser e dei valori dei parametri.
Guarda anche:
Sintassi
window.open(URL, name, specs, replace)
Parametri
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: . |
Valore di ritorno
Un riferimento alla nuova finestra o null se la chiamata non è riuscita. |
Altri esempi
Apri una pagina about:vuota in una nuova finestra/scheda:
var myWindow = window.open("", "", "width=200,height=100");
Apri una nuova finestra chiamata "MsgWindow" e scrivici del testo:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
Sostituisci la finestra corrente con una nuova finestra:
var myWindow = window.open("", "_self");
myWindow.document.write("<p>I replaced the current window.</p>");
Apri una nuova finestra e controlla il suo aspetto:
window.open("https://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
Apri più schede:
window.open("http://www.google.com/");
window.open("https://www.w3schools.com/");
Apri una nuova finestra. Usa close() per chiudere la nuova finestra:
function openWin() {
myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window
}
function closeWin() {
myWindow.close(); // Closes the new window
}
Apri una nuova finestra. Utilizzare la proprietà name per restituire il nome della nuova finestra:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
Utilizzando la proprietà opener per restituire un riferimento alla finestra che ha creato la nuova finestra:
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
Supporto browser
open()
è supportato in tutti i browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |