Added onbeforeunload handler/prompt (refs #4074)

A onbeforeunload handler is set to prevent accidental closure of window or tab.