покинуть страницу

window.onbeforeunload = function(){
  myfun();
  return 'Are you sure you want to leave?';
};
Xerothermic Xenomorph