Thuộc tính opener của đối tượng Window trong HTML DOM trả về tham chiếu đến cửa sổ cha đã khởi chạy/tạo cửa sổ con bằng phương thức open().
Cú pháp
Trả về tham chiếu cửa sổ cha:
window.opener
Ví dụ
Ví dụ minh họa thuộc tính HTML DOM Window opener:
<!DOCTYPE html> <html> <head> <title>HTML DOM Window opener</title> <style> * { padding: 2px; margin:5px; } form { width:70%; margin: 0 auto; text-align: center; } input[type="button"] { border-radius: 10px; </style> </head> <body> <form> <fieldset> <legend>HTML-DOM-Window-opener</legend> <input id="urlSelect" type="url" placeholder="Nhập URL..."><br> <input type="button" value="Đi đến" onclick="openWindow()"> <input type="button" value="Đóng" onclick="closeWindow()"> <input type="button" value="Khôi phục" onclick="restoreWindow()"> <div id="divDisplay"></div> </fieldset> </form> <script> var urlSelect = document.getElementById("urlSelect"); var winSource; function openWindow() { browseWindow = window.open(urlSelect.value, "browseWindow", "width=400, height=200"); winSource = urlSelect.value; browseWindow.opener.document.getElementById("divDisplay").textContent = "Cửa sổ con hoạt động"; } function closeWindow(){ if(browseWindow){ browseWindow.close(); browseWindow.opener.document.getElementById("divDisplay").textContent = "Cửa sổ con đã đóng"; } } function restoreWindow(){ if(browseWindow.closed){ browseWindow = window.open(winSource, "browseWindow", "width=400, height=200"); browseWindow.opener.document.getElementById("divDisplay").textContent = "Cửa sổ con đã khôi phục"; } } </script> </body> </html>
Kết quả
Nhấn nút „Đi đến“ với trường URL đã đặt:

Nhấn nút „Đóng“:

Nhấn nút „Khôi phục“:
