When we want to do something with javascript when a user closes an Explorer window, we simply handle the body onunload event. But when a user is working in an explorer that has more than one tab open, this event doesn't work when we want to do something if the user closes a tab, not the explorer window. So, if we need to do something when a user closes an explorer tab and since a browser tab is a window, we can simply handle the window.onbeforeunload event:
<script language="javascript" type="text/javascript">
window.onbeforeunload = opengoodbyepage;
function opengoodbyepage()
{
window.open('bye.aspx', 'popUpWin',
"toolbar=no,location=no,menubar=no,resizable=no,width=410,height=300,top=300,left=400");
}
</script>