How to block user from returning to previous browser page

Asked

Viewed 2,014 times

1

Is there any method that makes a user unable to return to the previous page?

I happen to have a contact form in which the person must complete and ready. It is not possible to return and fill again.

It’s like the browser tab creates a new section, or something like.

It is possible to make the option return to the previous page "blocked"?

1 answer

2


This script will override attempts to navigate back and forth with the current page state.

history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
    history.pushState(null, null, document.URL);
});

The pushState changes the referrer that is used in the HTTP header for Xmlhttprequest objects created after changing the state.

See more about.

Note that this code is not cross-browser, use for your responsibility.

UPDATING

The pushState method is compatible with

Chrome - 5 >
Firefox (Gecko) - 4.0 (2.0) >
Internet Explorer - 10 >
Opera - 11.50 >
Safari - 5.0 >
  • Is that code right? You said pushState, but the code is popstate.

  • 1

    I referred to the pushState method.

  • I’m going to test it now!

  • Perfect! It worked! Thank you very much!

  • Which version of your browser and which browser ?

  • I am using Maxthon Cloud Browser, it has some incompactibility problem with some browser?

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.