نافذة مفتوحة ()
مثال 1
افتح "www.w3schools.com" في علامة تبويب متصفح جديدة:
window.open("https://www.w3schools.com");
المزيد من الأمثلة أدناه.
التعريف والاستخدام
تفتح open()
الطريقة نافذة مستعرض جديدة ، أو علامة تبويب جديدة ، بناءً على إعدادات المستعرض وقيم المعلمات.
أنظر أيضا:
بناء الجملة
window.open(URL, name, specs, replace)
المعلمات
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: . |
قيمة الإرجاع
إشارة إلى النافذة الجديدة ، أو فارغة إذا فشلت المكالمة. |
مزيد من الأمثلة
افتح حول: صفحة فارغة في نافذة / علامة تبويب جديدة:
var myWindow = window.open("", "", "width=200,height=100");
افتح نافذة جديدة تسمى "MsgWindow" ، واكتب بعض النص فيها:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
استبدل النافذة الحالية بنافذة جديدة:
var myWindow = window.open("", "_self");
myWindow.document.write("<p>I replaced the current window.</p>");
افتح نافذة جديدة وتحكم في مظهرها:
window.open("https://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
افتح عدة علامات تبويب:
window.open("http://www.google.com/");
window.open("https://www.w3schools.com/");
افتح نافذة جديدة. استخدم إغلاق () لإغلاق النافذة الجديدة:
function openWin() {
myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window
}
function closeWin() {
myWindow.close(); // Closes the new window
}
افتح نافذة جديدة. استخدم خاصية الاسم لإرجاع اسم النافذة الجديدة:
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
استخدام خاصية opener لإرجاع مرجع إلى النافذة التي أنشأت النافذة الجديدة:
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
دعم المتصفح
open()
مدعوم في جميع المتصفحات:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |