Evento de fechamento de janelas JS

window.onbeforeunload = function(){
  alert("You are now leaving, are you sure?")
}
DatMADCoder