skip to Main Content

I have tried this, but the back page is showing for 1 or 2 secs and after that it comes back to the current page. I don’t want to go to Backpage even for 1 or 2 sec.

<script type="text/javascript">
    function preventBack() { window.history.forward(); }
    setTimeout("preventBack()", 0);
    window.onunload = function () { null };
</script>

I have write this code in Asp.net .aspx file.

Is their any other way?

2

Answers


  1. What you are wanting to do is client side logic. So asp.net vs node vs php doesn’t really enter into this.

    You are on the correct track. I’d suggest adding a window.history.pushState({}, ”, window.location) to your initial code so the browser sees the first back button press as hitting the same page. Also check out window.onhashchange

    Login or Signup to reply.
  2. I think this snippet will help you out:

    window.history.pushState(null, null, window.location.href);
        window.onpopstate = function () {
            window.history.go(1);
        };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search