A same-origin child window can request a reload of the window that opened it through window.opener.location.reload(), then close itself. This pattern can be useful after the child completes an update that the parent should display.
Please read the child window open and child window close tutorials before trying this.
<button type="button" id="openChild">Open Window</button>
<script>
document.getElementById("openChild").addEventListener("click", () => {
window.open("window-child2.html", "Ratting", "width=550,height=170,left=150,top=200,toolbar=0,status=0");
});
</script><!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Refresh parent from child</title></head>
<body>
<p>This is the child window. Click the button to refresh the parent and close this window.</p>
<button type="button" id="refreshParent">Close this window</button>
<script>
document.getElementById("refreshParent").addEventListener("click", () => {
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
}
window.close();
});
</script>
</body>
</html>Direct opener access depends on the opener being present and browser policy allowing the relationship. If all you need is to notify another page of a data change, consider application-level state or messaging rather than forcing a full reload.
Window object Reference Passing data from Child window to parent window
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| muzzamil | 01-09-2014 |
| Is there any way to open the left portion of a page in a popup window?? if possible help me to do it.... | |