This is a basic script that I re-arranged into a usfull tool for webmasters. Try pressing the back button and see what happens. When the viewer tries to go to another page, a confirm box comes up asking them if they really want to leave. If they say no, then the script will reload the current page (sorry, no way around that). Some viewers may be annoyed by the box, so I would just recommend using this for your main page.
The source..


<script language="Javascript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

var your_message = "Do you really want to leave this page?";
var times = 0;

function onul() {
if (times == 0) {
  var leave = confirm(your_message);
  if (!leave) location = self.location;
  times++;
}
}

//-->
</script>
<body onunload="onul()">

Nic's Javascript Page