'Why is event.ClientY always negative on some client machines?
We have an application that is installed on an intranet and is accessed with IE. There are certain things that we want to do if the user closes the browser (e.g. using the X in the upper right hand corner of the browser) but not if the user clicks on a link to go to a different page. So in JavaScript, we want to detect this condition. The most common solution suggested is that in the onunload
or onbeforeunload
function, check to see if event.ClientY
is negative. If it's negative, then the user has clicked the X to close the browser. I know this is not completely reliable, but it only needs to work in IE. Here's an example:
http://www.coderanch.com/t/122627/HTML-CSS-JavaScript/Generic-code-Detect-Brower-Close
Here's our problem: There are certain client computers where, when the user clicks on a link on the page that is supposed to send them to another page, the event.clientY
value is always negative, which then runs our JavaScript that is only supposed to be run when they close the browser. event.clientX
and event.clientY
are always stuck as the same negative values, no matter where the link is on the page that I click on. I can't see anything different on the client computers that do this (e.g. IE version or settings or compatibility view or if the server is a trusted site). If I alert event.clientY
in an onclick
function, it seems to be correct. It's only stuck as a negative value in the onunload
and onbeforeunload
functions.
Any ideas on why this is happening, or what IE settings might be causing it?
Solution 1:[1]
The javascript in the OP was broken by this Microsoft July 2013 update (this is even acknowledged in the "Known issues" section):
http://support.microsoft.com/kb/2846071/en-gb
But it was fixed in this August 2013 update:
http://support.microsoft.com/kb/2862772
I have confirmed that clients on which I install the Aug update no longer have the issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | John Gilmer |