我需要限制整个应用程序中的退格导航。是否有任何解决方案,即我可以在一个地方为整个应用程序执行的操作?
最佳答案
angular.module('yourModule', [])
.controller('yourController', ['$scope', '$document', function($scope, $document) {
$document.on('keydown', function(e){
if(e.which === 8 && ( e.target.nodeName !== "INPUT" && e.target.nodeName !== "SELECT" ) ){ // you can add others here inside brackets.
e.preventDefault();
}
});
}
]);
除非任何输入标记处于事件状态,否则它将阻止退格导航。
我们还没有对文本区域进行处理,因此它不允许在文本区域上退格。
关于javascript - 有没有办法防止整个 AngularJS Web 应用程序中的退格导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37720598/