[英]prevent back button on to previous page - angularjs
From within my controller, I am attempting to disable or prevent back button from within an angularjs controller after making a get request and navigating to a page. 在我的控制器中,我尝试在发出获取请求并导航到页面后禁用或阻止angularjs控制器中的后退按钮。 The disabling of the back button or prevent going back to the previous page has not happened.
没有发生过禁用后退按钮或阻止返回上一页的情况。 This is my snippet
这是我的片段
$scope.goToDashboardAfterLogin= function () {
$http({
method: 'GET',
url: '/page',
else if (response.status == 200) {
$(window).on("keypress", function (e){
if(e.keycode == "backspace")
e.preventDefault();
})
$(location).attr('href', '/page2');
}
}, function errorCallback(response) {
alert(JSON.stringify(response));
});
};
how can I achieve prevent going back to the previous page from the browser from tha above attempt 我该如何防止以上尝试从浏览器返回上一页
Did you try 'return false'? 您是否尝试过“返回假”?
$(window).on("keypress", function (e){
if(e.keycode == "backspace")
return false;
});
e.preventDefault() will prevent the default event from occuring, e.stopPropagation() will prevent the event from bubbling up and return false will do both. e.preventDefault()将阻止默认事件的发生,e.stopPropagation()将阻止事件的冒泡并返回false会同时执行这两项操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.