Added onbeforeunload handler/prompt (closes #4074)