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?
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?
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>