Pencere açık()
örnek 1
"www.w3schools.com"u yeni bir tarayıcı sekmesinde açın:
window.open("https://www.w3schools.com");
Aşağıda daha fazla örnek.
Tanım ve Kullanım
Yöntem open()
, tarayıcı ayarlarınıza ve parametre değerlerine bağlı olarak yeni bir tarayıcı penceresi veya yeni bir sekme açar.
Ayrıca bakınız:
Sözdizimi
window.open(URL, name, specs, replace)
parametreler
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: . |
Geri dönüş değeri
Yeni pencereye bir referans veya çağrı başarısız olursa null . |
Daha fazla örnek
Yeni bir pencerede/sekmede about:boş bir sayfa açın:
var myWindow = window.open("", "", "width=200,height=100");
"MsgWindow" adlı yeni bir pencere açın ve içine bir metin yazın:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
Geçerli pencereyi yeni bir pencereyle değiştirin:
var myWindow = window.open("", "_self");
myWindow.document.write("<p>I replaced the current window.</p>");
Yeni bir pencere açın ve görünümünü kontrol edin:
window.open("https://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
Birden çok sekme açın:
window.open("http://www.google.com/");
window.open("https://www.w3schools.com/");
Yeni bir pencere açın. Yeni pencereyi kapatmak için close() işlevini kullanın:
function openWin() {
myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window
}
function closeWin() {
myWindow.close(); // Closes the new window
}
Yeni bir pencere açın. Yeni pencerenin adını döndürmek için name özelliğini kullanın:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
Yeni pencereyi oluşturan pencereye bir referans döndürmek için opener özelliğini kullanma:
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
Tarayıcı Desteği
open()
tüm tarayıcılarda desteklenir:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |