Reputation: 570
So i am building a 'like' button but i have a small problem after the user login's in through the little window, the user has to refresh the whole page. I want it to check if the window has closed and then refresh the iframe. So I have this code to open the pop-up and i've been looking at the at this post for help, but it's not helping that much. Check if a popup window is closed
function grubber_highlight()
{
var popup = window.open("http://www.grubber.co.nz/login/", "newwindow", config="height=600,width=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no");
var windowloc = document.URL;
var windowlocation = (windowloc + "&highlight=t");
window.location = windowlocation;
if (popup) {
popup.onclose = function () { alert("closed"); }
}
}
I have this code to check if the window has closed and then alerts me that it has worked
if (popup) {
popup.onclose = function () { alert("closed"); }
}
The little window goes here http://www.grubber.co.nz/login/ if anyone want's to know.
I also want it to be able to work on most browser newer that ie8
edit I googled a but deeper and found onunload it works on the closing but it also fires up when i open the window also...
Question
how to detect when the window is closed and then refresh the iframe
Upvotes: 2
Views: 3028
Reputation: 19252
Supposed this is how the popup is opened:
win = window.open(...);
Then, you should repeatedly check if the popup is closed.
var timer, win;
function polling(){
if (win && win.closed) {
clearInterval(timer);
alert('popup window is closed.');
}
}
timer = setInterval('polling()',100);
UPDATED: Another technique is discussed here
Upvotes: 2
Reputation: 570
Ok thanks guy's but i go the answer i wanted with the onunload event
var popup = window.open("http://www.grubber.co.nz/login/", "newwindow", config="height=600,width=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no");
var windowloc = document.URL;
var windowlocation = (windowloc + "&highlight=t");
window.location = windowlocation;
var e = 0;
if (popup) {
popup.onunload = function () {
if (e == 1)
{
//this will reload the iframe
alert("closed");
}
else
{
//this will be when the pop-up gets created
e++;
}
}
Upvotes: 1