Unfortunately there isn't really any way of doing this. If you could, then the spam sites would have a field day.
You could potentially use window.onbeforeunload and have a global boolean variable on the page that you set to false if you don't want to trigger the event. For example, before submitting the form, set it to false, or when a link is clicked on the page, set it to false. Then just check against the variable.
EDIT: Sorry, just to be clear, I'm not sure if window.onbeforeunload even fires when the back button is clicked. I'm just talking hypothetically if it does.