Confirme antes de sair da página JavaScript

//says: do you want to leave this site changes may not be saved
window.onbeforeunload = function(e) {
  return "Do you want to exit this page?";
};
Dangerous Deer