[英]How to disable the browser back button with java script, ruby on rails
How to disable the browser back button while navigating in our application. 如何在我们的应用程序中导航时禁用浏览器后退按钮。 I already try with the following code it prevent only go back option not hide or disable the back navigation icon.
我已经尝试使用以下代码,它只防止返回选项不隐藏或禁用后退导航图标。
<script type = "text/javascript" >
history.pushState(null,null);
window.addEventListener('popstate', function() {
history.pushState(null,null); });
</script>
<script type="text/javascript">
window.history.forward();
</script>
I want to know atleast able to mask that browser back navigation icon/button(it like open new tap in browser that navigation button display as mask mode). 我想知道至少能够掩盖浏览器后面的导航图标/按钮(就像在导航按钮显示为掩码模式的浏览器中打开新点击一样)。
You cannot or better: you should not. 你不能或更好:你不应该。
And if you can, it's an unsecure and unreliable browser. 如果可以的话,这是一个不安全且不可靠的浏览器。
Best practice says don't mess with the back button, the USER EXPERIENCE will suffer. 最佳实践说不要乱用后退按钮,用户体验将受到影响。
EDIT: 编辑:
You can try to funnel the user by manipulating a session variable on the server-side. 您可以尝试通过在服务器端操作会话变量来漏斗用户。 Keep a variable like
page_number
in the session, then set it to 0
on the first page. 在会话中保留类似
page_number
的变量,然后在第一页上将其设置为0
。
On all subsequent pages check the page_number
and force a server-side redirect if the page number is wrong. 在所有后续页面上检查
page_number
并在页码错误时强制进行服务器端重定向 。
For example, on page 4
you would do this: 例如,在第
4
页上,您将执行此操作:
if (session.page_number === 3)
{
// ok, user comes from previous page
session.page_number = 4;
} else {
// server-side redirect back to proper page
// which happens to be "session.page_number"
}
You put that code on each page (setting higher/lower page numbers) and a back-button click will cause a redirect to the same page you were before. 您将该代码放在每个页面上(设置更高/更低的页码),然后单击后退按钮将导致重定向到您之前的同一页面。
Obviously, this is a very bad practice. 显然,这是一种非常糟糕的做法。 Funnels should be used only in very limited cases such as for shopping carts and credit card scenarios.
漏斗应仅在非常有限的情况下使用,例如购物车和信用卡场景。 A funnel causes a web page to behave more like an ATM.
漏斗使网页的行为更像ATM。 Air flight companies and Amazon use funnels.
航空公司和亚马逊使用漏斗。
You can find exact details about server-side redirects for ruby on rails on the Internet. 您可以在Internet上找到有关ruby on rails的服务器端重定向的确切详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.