Hi I have this code where i tried to get mouse position when i try to unload the page.
Each time i run code and alert gives me unidentified value.
Here is my output,
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script>
var mouse = {x: 0, y: 0};
 
document.addEventListener('mousemove', function(e){ 
    mouse.x = e.clientX || e.pageX; 
    mouse.y = e.clientY || e.pageY 
}, false);
if (window.addEventListener) {  // all browsers except IE before version 9
 window.addEventListener("beforeunload", function (e) {
    var confirmationMessage = "Hi";
    alert(mouse.x + ' : ' + mouse.y);     
     return confirmationMessage;                            
  });
}
else {
    if (window.attachEvent) {   // IE before version 9
     window.attachEvent("beforeunload", function (e) {
           var confirmationMessage = "Hi";
    alert(mouse.x + ' : ' + mouse.y);
     return confirmationMessage;                            
  });
    }
}
</script>
</head>
<body>
  <h1>This is a Heading</h1>
  <p id = "myAns">This is a paragraph.</p>
</body>
</html>I modified code that you guys suggested. So my problem is then how to find out when user click on close button of browser or close button of tab ?
because I thought that when user clicks out of document then mouse position is 0 and we can tell that user clicked on close button "beforeUnload" is called.
Thanks in advance.
 
    