Thuộc tính parent của đối tượng Window trong HTML DOM trả về tham chiếu đến cửa sổ cha của cửa sổ con.
Cú pháp
Trả về tham chiếu cửa sổ cha:
window.parent
Ví dụ
Ví dụ minh họa thuộc tính HTML DOM Window parent:
<!DOCTYPE html> <html> <head> <title>HTML DOM Window parent</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-parent</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; parent.document.getElementById("divDisplay").textContent = "Cửa sổ con hoạt động"; } function closeWindow(){ if(browseWindow){ browseWindow.close(); parent.document.getElementById("divDisplay").textContent = "Cửa sổ con đã đóng"; } } function restoreWindow(){ if(browseWindow.closed){ browseWindow = window.open(winSource, "browseWindow", "width=400, height=200"); parent.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“:
