I have page A that creates a window with the page B.
Page B asks the user some datas, inserts them in the database and then closes itself. After the insertion, I'm trying to make page A refresh automatically (it can be both from A seeing that B has closed, or by a function triggered by B itself before (or after?) closing)
How can I do that?
I have page A that creates a window with the page B.
Page B asks the user some datas, inserts them in the database and then closes itself. After the insertion, I'm trying to make page A refresh automatically (it can be both from A seeing that B has closed, or by a function triggered by B itself before (or after?) closing)
How can I do that?
Share Improve this question edited May 31, 2013 at 8:40 Mewster asked May 31, 2013 at 8:35 MewsterMewster 1,0633 gold badges11 silver badges27 bronze badges 2-
possible through JavaScript
window.onclose
, no? Or you trying to do this through PHP only? – BlitZ Commented May 31, 2013 at 8:39 - Well maybe, but how can I address page A in this way? (both php or javascript are ok, editing tag) – Mewster Commented May 31, 2013 at 8:40
3 Answers
Reset to default 2JavaScript's window.open()
returns reference to the instance of opened window. You may use it to set up onunload
event handler, like this:
var hWndB = window.open('somepage.php'),
hWndA = window.self;
hWndB.onunload = function(){ hWndA.location.reload(); }
You can use the onunload
event and window.opener
. For example.
window.addEventListener('unload', function() {
window.opener.location.reload();
}, false);
Or you could use jquery so you wouldn't have any crossbrowser patibility problems:
$(window).on('unload', function() {
window.opener.location.reload();
});
Also there is another event called onbeforeunload
that you might want to take a look at.
EDIT
For older browser you can use the hack that @CORRUPT has provided in the ments: window.open() returns undefined or null on 2nd call
Variant "A seeing B closed":
//winb is global variable
winb=window.open(blah blah); //Existing: A opens B
window.setTimeout(checkWinB,1000);
function checkWinB() {
if (winb.closed()) refreshMySelf();
else window.setTimeout(checkWinB,1000);
}
Variant "B kicks A":
opener.rerfreshMySelf();
window.close() //Existing: B closes
Both variants need the refreshMySelf()
function to refresh the page. How to do this depends on the page mechanism, but a starting point for a non-AJAX page is
function refreshMySelf() {
location.reload();
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744939650a4602244.html
评论列表(0条)