Evento de cierre de la ventana JS

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