[英]How to disable browser back button in AngularJS?
i want disable browser back button and refresh button. 我想禁用浏览器后退按钮和刷新按钮。 in angular
在角度
example my source 我的例子
page source : 页面来源:
"use strict";
.controller("wizardSecondController", function($scope, $state, $stateParams, wizardManager) {
$scope.$on("$viewContentLoaded", function(event, data) {
});
i want prevent browser back and refresh . 我想防止浏览器返回并刷新。 please answer .
请回答 。
If you want to disable browser back button in angular, please try out the following code. 如果您想禁用浏览器的后退按钮,请尝试以下代码。 It may help.
这可能会有所帮助。
$scope.$on('$locationChangeStart', function(event, next, current){
event.preventDefault();
});
I shall give you advice as to disabling the back button: 我将为您提供有关禁用后退按钮的建议:
Strictly speaking it isn't "possible" if using standards, but there are workarounds. 严格来说,如果使用标准,这是“不可能的”,但是有解决方法。
There is the window.history object which includes a small API . 有一个window.history对象,其中包含一个小的API 。
But it doesn't allow you to double check for states/pages before the user surfed to your site. 但是,它不允许您在用户浏览您的网站之前仔细检查状态/页面。 Obviously for security reasons and not by accident or missing implementation.
显然是出于安全原因,并非偶然或未实施。
There's various checks for the usage of navigating back in the history and several posts about that topic, but none is helpful as to when it comes to the point the user leaves your page and goes beyond your accessible history. 有很多检查历史回溯的用法,以及有关该主题的几篇文章,但是对于何时用户离开页面并超出可访问的历史记录,这些方法都无济于事。
As to that, check on the events 对此,检查事件
If you want to catch the user on your site for some hopefully incredibly good purpose: 如果您想在网站上吸引用户是出于某些令人难以置信的良好目的:
Et voila ... In my case I can't even escape our page if I hold down the backspace button ... 等等...就我而言,如果我按下退格键,我什至无法逃脱页面...
Another convenient option would be to put the page into fullscreen mode if feasible :) 另一个方便的选择是,如果可行的话,将页面置于全屏模式:)
Cheers, J 干杯,J
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.