i want to disable forward and back button of IE in jsp page

Dani AI

Generated

Short expert note for : there is no supported, cross-browser way for a web page (JSP or client script) to permanently disable the browser’s Back/Forward buttons. Those controls are part of the user agent and intentionally outside page control. As already hinted, trying to “turn them off” is brittle and will break expectations across browsers and assistive technologies.

Practical alternatives that actually solve real problems:

  • Prevent duplicate actions (the usual motivation): use server-side patterns — Post/Redirect/Get, single-use server tokens, idempotent handlers or a “consumed” flag on operations — so a back/refresh does not re-run a sensitive action.
  • Avoid stale-state issues: set appropriate response headers (for example, Cache-Control, Pragma, Expires) and validate every request server-side so going back doesn’t expose sensitive or replayable state.
  • Warn on accidental navigation for unsaved work by using the unload/confirmation mechanism, not by trying to block navigation entirely.

If controlling in-page navigation is acceptable (single-page app style), manage the history instead of trying to disable buttons: push logical states and handle the popstate event to restore UI or show a confirmation. Example pattern:

if (history && history.pushState) {
  history.pushState({guard:true}, '', location.href);
  window.addEventListener('popstate', function(e) {
    if (e.state && e.state.guard) {
      // restore UI or prompt; avoid permanently trapping the user
      history.pushState({guard:true}, '', location.href);
    }
  });
}

Caveats: do not trap users — that frustrates and breaks accessibility — and test across browsers (older IE quirks exist). As noted, the correct fix depends on the underlying requirement; focus on server-side safeguards and clear UX rather than trying to disable browser UI.

Recommended Answers

All 5 Replies

It is not possible you cannot control browser buttons from JSP/Javascript

technically true. But you could keep a record of where the user has been and when trying to get to the previous (next in that case wouldn't ever happen) URL simply reload the page they're on.

Hi jwenting, woudnt the user get confused when he/she clicks on back button and the current page reloads?
Could you elaborate more on this approach?


Also, long back had tried using

window.location.replace

but was not satisfied with it. Maybe was not able to implement it properly.

If you could shed more light on it, it would be useful as this is a very common scenario to deal with in web applications

i want to disable forward and back button of IE in jsp page

Perhaps it would be better to tell us WHY you want to disable the forward/back button. Maybe what you are trying to achieve can be done in another way than disabling the buttons.

Hi jwenting, woudnt the user get confused when he/she clicks on back button and the current page reloads?

Probably, but it would have the desired effect :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.