Just set

window.onbeforeunload = function() { return ‘message’; }

but not yet tested.