0

There are multiple windows in my project.I am using angular 1 I want to identify event when user close the window.

I have tried below function but it is not working in Fire Fox and Chrome as well as I am not able detect which window is closed

$window.onbeforeunload = function (event) { alert("Hi"); };

Please Help me How can I Identify event when user close particular window also How can I Detect which window is closed?

krish
  • 79
  • 1
  • 8
  • Are you sure you need to use $window? I think $window is a jQuery object. If it is, than you should use $window[ 0 ].onbeforeunload – elad.chen May 09 '17 at 09:47
  • @elad.chen $window is not a jquery object, it might be here meant to be a variable equal to a jquery object. – Amr Elgarhy May 09 '17 at 09:50
  • @elad.chen I think it is the [`$window` service](https://docs.angularjs.org/api/ng/service/$window) of angular, a wrapper around the `window` object of javascript – devqon May 09 '17 at 09:55
  • Yes $window service is a wrapper around the window obj of javascript – krish May 09 '17 at 10:15

1 Answers1

0

window.addEventListener("beforeunload", function (e) {
  var confirmationMessage = "\o/";

  (e || window.event).returnValue = confirmationMessage; //Gecko + IE
  return confirmationMessage;                            //Webkit, Safari, Chrome
});