There is, unfortunately, no javascript event to detect the clicking of the X button (closing of the browswer). The closest we come is the onunload or onbeforeunload events. And, yes, they fire regardless of the method that the user chooses to navigate away from the page. Whether by closing the browser, clicking a link, entering another URL, or reloading a page. This is what you've discovered.
Don't know if this will solve your problem since we StackOverflowers don't know about your app, but you could create a kludge similar to this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script language = "javascript">
function Message()
{
if (reallyExiting) alert("Are you sre you want to leave?");
}
</script>
</head>
<body onLoad="reallyExiting=true" onUnload="Message();">
<a href="example.html" onClick="reallyExiting=false">Not really leaving</a>
<a href="http://www.someOtherSite.com">Really leaving</a>
</body>
</html>
I know it's rough, but you could use some similar variable to keep track of what links they've hit or not hit as the case may be.
HTH.