Brawia
Brawia

Reputation: 33

Disable browser "Back" button

how can I disable the browser's "Back" button in a HTML page? I do not want to create JavaScript window to avoid showing any toolbar,etc. In regular HTML page, is there any way to disable the back button in the toolbar?

thanks

Upvotes: 0

Views: 4247

Answers (3)

Eng Mahmoud El Torri
Eng Mahmoud El Torri

Reputation: 503

Write this code between script tags

    history.pushState(null, null, location.href);
    window.onpopstate = function () {
        history.go(1);
    };

Upvotes: -1

Ira Rainey
Ira Rainey

Reputation: 5209

You can't technically disable it, and moreover you shouldn't. Disabling the back button of a browser would fundamentally change the browsing experience for a user which isn't your place to do.

If going back in the browser creates problems for your application then you should restructure your workflow so it doesn't. An example of this is implementing the POST/REDIRECT/GET pattern.

More Info: http://en.wikipedia.org/wiki/Post/Redirect/Get

Upvotes: 4

Pål Brattberg
Pål Brattberg

Reputation: 4698

There's no way to disable the Back-button using regular HTML as you specify.

Upvotes: 0

Related Questions