How to disable browser button using java script, ruby ​​on rails

How to disable the browser button while navigating in our application. I am already trying to use the following code which only prevents the return, does not hide or disable the inverse navigation icon.

<script type = "text/javascript" >
      history.pushState(null,null);
      window.addEventListener('popstate', function() {
          history.pushState(null,null); });
</script>

      

and

<script type="text/javascript">

  window.history.forward();

</script>

      

I want to know at least the ability to mask this navigation button / button for the browser (this is how to open a new click in the browser so that the navigation button appears as a mask).

+3


source to share


1 answer


You can't or better: you shouldn't.

And if you can, this is an insecure and untrusted browser.

Best practice says not to be confused with the back button, the USER EXPERIENCE will suffer.

EDIT:

You can try to direct the user by manipulating the session variable on the server side. Save the type variable page_number

in the session, then set it to 0

on the first page.

On all subsequent pages, check page_number

and force the server side to redirect if the page number is incorrect.



For example, on a page, 4

you would do the following:

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 this code on every page (set higher / lower page numbers) and clicking the back button causes it to redirect to the same page you were on before.

This is obviously very bad practice. Funnels should only be used in very limited cases such as shopping carts and credit card scenarios. The funnel causes the web page to behave like an ATM machine. Airlines and Amazon use funnels.

You can find exact information about server side redirection for rubies on rails on the internet.

+4


source







All Articles