Trap onbeforeunload when event fired (attempt to fix FS#2196)