make sure onbeforeunload only called once