well firstly, you can't really prevent them leaving the page. They could just close the tab, or browser, or just do nothing till the session times out.
But the message you're seeing is based on a before unload event. google for
javascript onbeforeunload
Cheers
Bruce