Fixing issue #291 (WIP)

remove the eventListener on beforeUnload as soon as this function is called