I am trying to reload a parent window if child window get closed.
Here is my current code which opens a popup window, but it has not programmed for refresh parent window when it get closed. I dont know what code to add
jQuery(document).ready(function($) {
jQuery('.top-buttons a').live('click', function(e){
e.preventDefault();
newwindow=window.open($(this).attr('href'),'','height=500,width=850');
if (window.focus) {newwindow.focus()}
return false;
});
});
I am trying to reload a parent window if child window get closed.
Here is my current code which opens a popup window, but it has not programmed for refresh parent window when it get closed. I dont know what code to add
jQuery(document).ready(function($) {
jQuery('.top-buttons a').live('click', function(e){
e.preventDefault();
newwindow=window.open($(this).attr('href'),'','height=500,width=850');
if (window.focus) {newwindow.focus()}
return false;
});
});
Share
Improve this question
asked Mar 15, 2013 at 5:33
user007user007
3,24314 gold badges49 silver badges78 bronze badges
3
- 1 So, Where are you stuck? – William Buttlicker Commented Mar 15, 2013 at 5:36
- read question carefully, i need a code which refresh parent window if child get closed – user007 Commented Mar 15, 2013 at 5:38
- It was difficult to dedeuce it from original question.Now after edit it says so. – William Buttlicker Commented Mar 15, 2013 at 5:40
6 Answers
Reset to default 2Try:
newwindow = window.open($(this).attr('href'), '', 'height=500,width=850');
newwindow.onbeforeunload = function () {
console.log("popup closed")
}
You can access the parent window from the child window using window.opener : example
So to reload the parent window just call window.opener.location.reload() documentation when you handle the close event.
Try the below code on close event of the child window
window.opener.location.reload();
You can use window.opener to access parent window and window.reload() to reload it when child window is closed.
Please refer below URLS:
how to access parent window object using jquery?
javascript: How Can a parent window know that its child window closed?
in the parent window define an unload event like
function doStuffOnUnload() {
alert("Unloaded!");
}
if (typeof win.attachEvent != "undefined") {
newwindow.attachEvent("onunload", doStuffOnUnload);
}
else if (typeof win.addEventListener != "undefined") {
newwindow.addEventListener("unload", doStuffOnUnload, false);
}
from here i took it from
you need window.opener
window.opener.location.href = window.opener.location.href;
should be added to the closing event of the window.