$(window).bind('beforeunload',function(){ alert('closing'); })
Above code only seems to work for desktop browsers.