Why jQuery sometimes overwrites window.onbeforeunload?
Ok, I've finally figured a solution, which is probably not the cleanest one - because I don't know the exact cause of the problem - but it works. I've put my beforeunload function into jQuery's load function so it is executed after DOM and other elements are loaded.
$(window).load(function () {
$(window).bind('beforeunload', function() { return 'Are you sure ?';} );
});