Is there a way to fire something when a user closes their browser

Is there a way to fire something when a user closes their browser

Either with a "X" or "exit"?