Deleted onbeforeunload because it is called if an attachment is
downloaded. A workaround could be to add "target=_blank" to the href.
But this opens a browser window for a short time which is an ugly
behavior.