Jendela terbuka()
Contoh 1
Buka "www.w3schools.com" di tab browser baru:
window.open("https://www.w3schools.com");
Lebih banyak contoh di bawah ini.
Definisi dan Penggunaan
Metode open()
ini membuka jendela browser baru, atau tab baru, tergantung pada pengaturan browser Anda dan nilai parameter.
Lihat juga:
Sintaksis
window.open(URL, name, specs, replace)
Parameter
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: . |
Nilai Kembali
Referensi ke jendela baru, atau null jika panggilan gagal. |
Lebih Banyak Contoh
Buka halaman about:blank di jendela/tab baru:
var myWindow = window.open("", "", "width=200,height=100");
Buka jendela baru bernama "MsgWindow", dan tulis beberapa teks ke dalamnya:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
Ganti jendela saat ini dengan jendela baru:
var myWindow = window.open("", "_self");
myWindow.document.write("<p>I replaced the current window.</p>");
Buka jendela baru dan kendalikan tampilannya:
window.open("https://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
Buka banyak tab:
window.open("http://www.google.com/");
window.open("https://www.w3schools.com/");
Buka jendela baru. Gunakan close() untuk menutup jendela baru:
function openWin() {
myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window
}
function closeWin() {
myWindow.close(); // Closes the new window
}
Buka jendela baru. Gunakan properti nama untuk mengembalikan nama jendela baru:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
Menggunakan properti pembuka untuk mengembalikan referensi ke jendela yang membuat jendela baru:
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
Dukungan Peramban
open()
didukung di semua browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |