如何更改浏览器的后退按钮功能,类似于 ASP.NET 中的电子商务网站
我有一个网络应用程序,其中应该自定义浏览器的后退按钮功能。就像,每当我们点击浏览器的后退按钮时,它应该带我们到登陆页面(登录页面),它应该显示错误消息,指出“会话已过期”。请重新登录'。
我已经浏览了很多帖子,即使在堆栈溢出中,我也看到很少的帖子。但对我来说没有任何作用。我使用的 java 脚本方法作为临时解决方法。基本上,这个 JavaScript 永远不允许我们返回。相反,它会让我们保持在同一页面。 JavaScript 我使用了
请帮助我自定义浏览器后退按钮的功能。 任何建议都会对我非常有帮助。
I have a web application, in which browser's back button functionality should be customized. It's like, whenever we click on browser's back button, it should take us to landing page(Login page), It should display error message saying that 'session expired. Please login again'.
I have gone through so many posts and even in stack overflow also, i saw few posts. But nothing worked for me. The java script approach i am using as a temporary workaround.Basically this JavaScript never allow us to go back. instead it will keep us in same page.
JavaScript i have used <script>history.go(1)</script>
Please help me to customize the functionality of Browser's back button.
Any suggestions will be really helpful to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短回答:你不能
再长一点:你甚至不应该尝试。
但如果你坚持:彻底检查“禁用后退按钮”。(从 2000 年开始,但由于它是 ASP,我想对您仍然有效:)
较新的点网:限制用户退出后返回上一页
忽略旧版浏览器不支持定位.replace - IE3.2 不再被认为是较旧的,而是古老的。
Short answer: You cannot
A little longer: You shouldn't even try.
But if you insist: A Thorough Examination of "Disabling the Back Button." (from 2000, but since it is ASP I guess still valid for you :)
Newer dot net: Restrict user go back to previous page after signout
Ignore the older browsers do not support location.replace - IE3.2 is not considered older any more but ancient.
为此 - 您需要一个自定义解决方案,并且禁用后退按钮不会有帮助......
通常您不应该尝试更改后退按钮的行为。但由于这是要求,我建议采用以下方法:
方法 1:
这需要创建一个导航框架,您可以在其中知道哪个是流程中的当前页面...只有当您按照页面顺序排列时,这才有可能被调用(像向导一样)
方法 2:
针对您的情况:您可以使用 jquery/javascript 来识别是否单击了后退按钮。如果是,那么您可以对服务器进行 ajax 调用来终止会话,然后重定向用户登录页面。
For this - you would need a custom solution and disabling back button will not help...
Usually you should not try to change the behavior of back button. But since this is the requirement, I would suggest the following:
Approach 1:
This calls for creating a navigation framework where you know which is the current page in the flow... This is only possible if you a sequence in which the pages will be called (like a wizard)
Approach 2:
Specific to your case : You can use jquery/javascript to identify if the back button is clicked.. If it is then you can do an ajax call to server to kill the session and then redirect the user to login page.
您可以使用如下方式以编程方式操纵浏览器历史记录:
window.history.back();
window.history.forward();
window.history.go(2); 在像 Chrome这样
支持 HTML5 的现代浏览器中,您还可以执行更高级的操作,包括使用 History.pushState() 和 History.replaceState() 方法完全覆盖后退按钮功能。
(https://developer.mozilla.org/en/DOM/Manipulated_the_browser_history)
您还可以使用 javascript + ajax 调用专门对后退按钮事件做出反应,但这在某些浏览器上也不起作用。您所要求的不是网络的本机部分,因此无论您最终决定使用什么,它都不会很容易或得到广泛支持。
You can programmatically manipulate browser history using something like this:
window.history.back();
window.history.forward();
window.history.go(2); etc.
In HTML5 ready modern browsers like Chrome you can also do more advanced things including completely overwriting back button functionality using history.pushState() and history.replaceState() methods.
(https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history)
You can also go dirty and use javascript + ajax calls to react specifically to back button events, but this will also not work on some browsers. What you ask is not a native part of a web, so no matter what you will decide to use in the end, it wont be very easy or widely supported.