0

I need to attach some event to my popup while my window is being closed and I can't figure out how to do this.

$scope.loginWithOk = function() {
  var left, popup, top;
  $window.$scope = $scope;
  left = screen.width / 2 - 250;
  top = screen.height / 2 - 250;
  popup = $window.open('/auth/odnoklassniki', '', 'top=' + top + ',left=' + left + ',width=700,height=500');
};

How can I do this?

When I go with

popup.onclose = function() {
  return alert(2222222222);
};

I can't see any alert so this option doesn't seem to be working.

Alex Nikolsky
  • 2,087
  • 6
  • 21
  • 36
  • See if this helps you - http://stackoverflow.com/questions/14809686/showing-alert-in-angularjs-when-user-leaves-a-page – v1shnu Sep 18 '15 at 14:21

1 Answers1

0

You can try using window.onunload

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onunload

More details as requested:

popup.onunload = function() {
  return alert(2222222222);
}
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
  • Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Heretic Monkey Sep 18 '15 at 14:19
  • I agree Mike, but the question needs more details for me to provide more details. – Dane O'Connor Sep 18 '15 at 14:21
  • Then perhaps you should comment on the question, asking the OP to provide more details? Perhaps also vote to close as unclear? Partially answering an unclear question seems the wrong way around... – Heretic Monkey Sep 18 '15 at 14:23
  • You have a point, for sure. The title was enough for me to give a concrete answer. While not very detailed - it's still accurate. It's too boarder line to close IMO. – Dane O'Connor Sep 18 '15 at 14:26
  • Gentlemen, we'll have to respectfully disagree. The answer to the question is simply: "use this API". I showed the API and pointed to the docs for whatever other information someone might need. I don't think an example illuminates anything here as it's basic javascript. I'll update my answer so you can see what I mean. – Dane O'Connor Sep 18 '15 at 18:15