0

I want to call a function in angularJs everytime when I close the tab of browser. For this I have written this code:

$window.onbeforeunload = function() {
    $scope.clientLogout('login');
};

$scope.clientLogout() is defined in the parent controller. Now when I close the tab from the parent controller, its working fine but its not able to call $scope.clientLogout() function when in child Controller.

I have also tried the below code and its working fine:

$window.onbeforeunload = function() {
    return ('hi');
};

Can anyone explain me?

Rohit
  • 221
  • 1
  • 7
  • `onbeforeunload` is not reliable, it executes whatever it has time to execute before the browser closes, but it doesn't stop the browser from closing a tab, for obvious reasons (spam), so you'll never know if there was time enough to log out the client or not. – adeneo Dec 11 '15 at 14:39
  • Can u tell me what should I use in this case?? – Rohit Dec 11 '15 at 18:44

0 Answers0