There is not as such close event available in Javascript. You can give message onUnload event. But that doesn't prevent application from closing. This function will execute when user click on any link, submitting the form etc.
window.onunload=function(){SomeJavaScriptCode};
For reference: http://www.w3schools.com/jsref/event_onunload.asp