Added onbeforeunload handler.