No going back: Preventing back button clicking in a browser

d0ef_back_to_the_future_mark1_delorian.jpgA quick tip. When building a single page app, you can prevent the user from pressing the back button in several ways. Here’s the way that seems to be the most effective, and simplest.

history.pushState(nullnull, location.href);
window.onpopstate = function () {
    history.go(1);
    alert("The back button should not be used.");
};


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s