I agree with Damien's point here that you're solving the wrong problem. I wrote a blog post on this
As a web developer, you have full control of your server code but only
limited control of the client in terms of scripting. You cannot even
gaurantee that the client will have any scripting capabilites (a user
may disable script until they trust your site), so
you should never design your site behaviour from the client's
perspective - i.e. trying to disable the back button of a browser.
Instead, if you need to implement behaviour so that when a logged out
user clicks the back button they are redirected to a login page, you
need to design your site so that this will occur. Your server side
design should drive the client behaviour
Full blog post is here - http://www.dylanmorley.com/blog/post/Web-Development-Disabling-the-back-button.aspx
While you can achieve the desired result using javascript, you cannot guarantee consistent behaviour across all devices in all modes (e.g - mobile browsing with script disabled)
Designing your server side code correctly will result in the correct client behaviour, without breaking the expected behaviour of the back button, with or without script enabled.