I'm going to make a few assumptions to present a way to do this that isn't fully reliant on javascript:
- You noted in the comments to another answer that this is an ASP.NET app. I am going to assume that you only care about the back button where it is being pressed from another page in your ASP.NET app.
- You control the server-side code executed in the ASP.NET code-behind for both the page in question and for the page(s) it will need to "back" out of.
If both of those conditions are true, then you should be able to use a Session variable! Just set the current page into a currPage variable maintained by session on all of the related pages. Then when the page is loading, check that and use it to either adjust the way the page is shown directly, or to write a value to a hidden field/input/div, which your javascript can read and use to react appropriately.
If you go the JS-read-and-execute route, you'll want to test to ensure the events fire properly on all browsers after a load-from-back-button. As mentioned in the link from Rionmonster, sometimes onload events may not fire after a back-button. If you see issues from this, then use the tricks mentioned there to get around it.
This type of solution should work for any web-app that employs server-side code capable of interacting with Session variables (e.g. it will also work for PHP, Python, and many others).
Note: There's a chance this won't be quite as elegant as it sounds. In a lot of cases browsers may not actually pull a fresh page from the server after the back button is pressed. If testing reveals this to be an issue, you may need to employ some AJAX techniques to populate the information fresh to the JS after the back button-press.