beforeunload event, fixes #33