Se il browser utilizzato e' IE allora puoi sfruttare l'evento onbeforeunload ... cerca su MSDN

ciao