save state onbeforeunload