Friday, 6 December 2013

Disable back button of your browser using javascript(Cross browser compatible)

It is an interesting browser hack and which uses hash values to prevent the default functionality of browser back button.But it and can be very annoying to use in your website and may be your user can dump your website . So please don't use that until if you have a really valid reason for it.

just at the top of your script .It set the hash value to 'no-back-button' at the time of page load.
How To Working   Click here for Demo

When a user clicks back button first time then the hash value set by first line of Javascript code gets changed triggering the onhashchange event written in second line.And then the function written in second line again sets the hash value to 'no-back-button' making the situation same as before when the user didn't click any button.
    window.location.hash="Again-No-back-button";//again because google chrome don't insert first hash into history

No comments:

Post a Comment