admin管理员组文章数量:1313614
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.
本文标签: jqueryjavascriptreload parent window if child window was closedStack Overflow
版权声明:本文标题:jquery - javascript - reload parent window if child window was closed - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741950067a2406658.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论