-2

I need to customize the browser alert box text when we click on browser close ('x') button of respective tab. I tried with window.onbeforeunload but it's not working for me.

Can any one help me using angular?

clami219
  • 2,958
  • 1
  • 31
  • 45
raj
  • 67
  • 1
  • 12

1 Answers1

0

It should be as simple as this:

angular.module('app', [])
  .controller('exitController', function($scope, $window) {
    $scope.onExit = function() {
      return ('leaving page');
    };

   $window.onbeforeunload =  $scope.onExit;
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="exitController">
  <a href="http://www.google.com">Leave page</a>
</div>
Kyle Krzeski
  • 6,183
  • 6
  • 41
  • 52