How to achieve dialog box open whenever user tries to refresh or reload the page ?
I have tried many links that suggested me to deduct the keypress/keydown/beforeload/beforeunload of refresh but these have not worked somehow.
here is ,I have tried. with my scenario.
var App = angular.module('App', ['ngRoute']);
        // configure our routes
        App.config(function($routeProvider) {
            $routeProvider
                .when('/', {
                    templateUrl : 'home.html',
                    controller  : 'mainController'
                })
                .when('/about', {
                    templateUrl : 'about.html',
                    controller  : 'aboutController'
                })
                .when('/contact', {
                    templateUrl : 'contact.html',
                    controller  : 'contactController'
                });
        });
 App.controller('mainController', function($scope) {
        //but not here if the user refresh the page 
        $scope.message = 'MainCtrl!';                    
    });
    App.controller('aboutController', function($scope) {
        $scope.message = 'aboutController';
       // if this is the current controller and page being refresh by the user activity
       // prompt the user to save before you reload...
    });
    App.controller('contactController', function($scope) {
        $scope.message = 'contactController';
    // if this is the current controller and page being refresh by the user activity
       // prompt the user to save before you reload...
    });
 in index.html 
 --------------------
 <script> 
     //it is working . it is invoking in each page. But needs to invoke at certain controller means it should check 
     // it is current/exact page where user has to save data before reloading 
     jQuery(function () {          
    // to check and get page refreshed & reload 
    var myEvent = window.attachEvent || window.addEventListener;
    var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';  
    myEvent(chkevent, function (e) {  
        var confirmationMessage = ' ';   
        (e || window.event).returnValue = confirmationMessage;
        return confirmationMessage;
    });
    if (myEvent) {
        localStorage.clear();
        // redirect to 
        $state.go('gotohome');                                 
    }
});
</script>
Can anyone give me any functional example that would work in all types of browser?
Its so important for me , I am not able to do anyway.
Thanks.
 
     
     
    