简体   繁体   中英

Angularjs: capture the refresh event in the browser

In angularjs is possible handle the user clicking the Refresh button on the browser? There is any method that the framework expose to the developer?

Thanks

To handle the reload itself (which includes hitting F5) and to take action before it reloads or even cancel, use 'beforeunload' event.

var windowElement = angular.element($window);
windowElement.on('beforeunload', function (event) {
   //Do Something

   //After this will prevent reload or navigating away.
   event.preventDefault();
});

You can use $routeChageStart :

 $rootScope.$on('$routeChangeStart', function () {
            alert('refresh');
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM