Ask for confirmation when leaving a submittable publisher

Fixes #4235, supersedes #4418 and #4645.

For more information on `beforeunload` see
https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload
https://developer.mozilla.org/en-US/docs/WindowEventHandlers.onbeforeunload

> Note that in Firefox 4 and later the returned string is not displayed to the user. Instead, Firefox displays the string "This page is asking you to confirm that you want to leave - data you have entered may not be saved."