0

i have this page which opens up a popup. i want to refresh the parent after popup has been closed.. i used the function i found in stackoverflow

  var win = window.open("popup.html");

function doStuffOnUnload() {
     alert("Unloaded!");
  }

if (typeof win.attachEvent != "undefined") {
    win.attachEvent("onunload", doStuffOnUnload);
} 
else if (typeof win.addEventListener != "undefined") {
    win.addEventListener("unload", doStuffOnUnload, false);
}

which didn't do anything after i closed the pop up... what can i do achieve this? thanks...

gdoron
  • 147,333
  • 58
  • 291
  • 367
guitarlass
  • 1,587
  • 7
  • 21
  • 45

1 Answers1

1

You wrote the unload event in the wrong place. You added an unload event to the main page instead of to the popup...

 var win = window.open("popup.html"); // O.K.

All of this should be in the popup.html page...

function doStuffOnUnload() {
     alert("Unloaded!");
  }

 if (typeof win.attachEvent != "undefined") {
   win.attachEvent("onunload", doStuffOnUnload);
 } else if (typeof win.addEventListener != "undefined") {
  win.addEventListener("unload", doStuffOnUnload, false);
  }

You can use the unload jquery function:

$(window).unload(doStuffOnUnload);

unload docs

gdoron
  • 147,333
  • 58
  • 291
  • 367