There is quite a bit wrong in your code. First, you absolutely don't need to measure any mouse position or x,y coordinates do what you've asked.
This will work to create an alert when the user closes the window:
<!-- note: you're missing a doctype here! -->
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function unLoadFnc()
{
alert("Closing the window .. ");
}
</script>
</head>
<body onUnload="unLoadFnc();">
Sample Html.
</body>
</html>
There's no need for events, clientX, any of that. Perhaps though, you're not showing me the entire script or explaining the entire project. So, in the case that you DO need the event, you need to test if it's part of the
window object (IE) or not.
Here's how I would code it:
<!-- doctype excluded, you need to pick one -->
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function unLoadFnc(evt)
{
var e = (window.event) ? window.event : evt;
alert(e.clientX);
}
</script>
</head>
<body onUnload="unLoadFnc(event);">
Sample Html.
</body>
</html>
I hope you're noting a few things, such as the fact that your page needs a doctype declaration, the proper way to write a script tag, and the semicolon after your event handler assignment.
The goal is to pass in the event object, and in your function, create a variable to hold it, using the tertiary operator.
Note, in FireFox, if you ran this code, the alert would say "undefined". That's because the widget that closes the window (the 'X') isn't within the client, so
clientX would be undefined.
You'd actually have to click something in the client area to get a value.
For example, a button:
<!-- doctype excluded, you need to pick one -->
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function unLoadFnc(evt)
{
var e = (window.event) ? window.event : evt;
alert(e.clientX);
}
</script>
</head>
<body>
Sample Html.
<form>
<input type="button" onclick="unLoadFnc(event);" />
</form>
</body>
</html>