
<script type="text/javascript" language="Javascript">
window.onbeforeunload = function() {
  console.log('event');
  return false; //here also can be string, that will be shown to the user
}
</script>