There is now a mechanism in TurboLinks to cancel a page change.
Here's a lib I made that abstracts the fact that your user may or may not be using TurboLinks : https://gist.github.com/jbourassa/6529382
This code also allows you to simply have multiple handlers for unloading.
And I use it like that:
Unloader.register(function() {
return "Please don't go!!";
});
This will automatically be removed on the next successful page change.