add unbeforeunload event listener