如何禁用后退按钮作为基于会话 [英] How to disable back button as Per session Based

查看:78
本文介绍了如何禁用后退按钮作为基于会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想根据会话启用或禁用后退按钮可以引导或发送片段

Hi All,

I want to enable or disable back button as per session based can u guide or send snippets

推荐答案

一个人无法禁用浏览器后退按钮功能,只有可以做的事情就是阻止它们。



下面的JavaScript代码需要放在页面的头部,您不希望用户使用后退按钮重新访问:

One cannot disable the browser back button functionality only thing that can be done is prevent them.

Below JavaScript code needs to be placed in the head section of the page where you don’t want the user to revisit using the back button:
<script>
  function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};
</script>



假设有两页Page1.aspx和Page2.aspx以及Page1.aspx重定向到Page2.aspx。



因此,为防止用户使用后退按钮访问Page1.aspx,您需要将上述脚本放在Page1.aspx的head部分。



有关更多参考,请访问:使用JavaScript禁用浏览器后退按钮功能


无法禁用浏览器后退按钮,如果您使用java脚本尝试某些备用解决方案,则无法保证在所有浏览器上都能正常工作。我建议在每个页面的Page_Load事件中检查会话的空值,如果找到的会话值为null,则相应地重定向到登录页面。

它不会停止后退按钮,但它可以防止任何无效的回发到服务器。
Browser back button can not be disabled, if you try some alternate solution using java script then it is not guaranteed to work on all the browsers. I will suggest to check the session for null value in Page_Load event for each page and accordingly redirect to the login page if found session value null.
It will not stop the back button but it can prevent any invalid postback to the server.


Disable-Browser-Back-Button-Functionality-using-JavaScript [ ^ ]


这篇关于如何禁用后退按钮作为基于会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆