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?
在angularjs中可以处理用户点击浏览器上的Refresh按钮吗?框架有哪些方法可以向开发人员公开?
Thanks
2 个解决方案
#1
4
To handle the reload itself (which includes hitting F5) and to take action before it reloads or even cancel, use 'beforeunload' event.
要处理重新加载本身(包括按F5)并在重新加载甚至取消之前采取行动,请使用'beforeunload'事件。
var windowElement = angular.element($window);
windowElement.on('beforeunload', function (event) {
//Do Something
//After this will prevent reload or navigating away.
event.preventDefault();
});
#2
0
You can use $routeChageStart
:
你可以使用$ routeChageStart:
$rootScope.$on('$routeChangeStart', function () {
alert('refresh');
});
#1
4
To handle the reload itself (which includes hitting F5) and to take action before it reloads or even cancel, use 'beforeunload' event.
要处理重新加载本身(包括按F5)并在重新加载甚至取消之前采取行动,请使用'beforeunload'事件。
var windowElement = angular.element($window);
windowElement.on('beforeunload', function (event) {
//Do Something
//After this will prevent reload or navigating away.
event.preventDefault();
});
#2
0
You can use $routeChageStart
:
你可以使用$ routeChageStart:
$rootScope.$on('$routeChangeStart', function () {
alert('refresh');
});