I'm not 100% sure what you are after ultimately... but i think the javascript event "onbeforeunload" is what you need to use
http://www.google.com/search?q=javascript+onbeforeunload
I'm not 100% sure what you are after ultimately... but i think the javascript event "onbeforeunload" is what you need to use
http://www.google.com/search?q=javascript+onbeforeunload