Ticket #1834 (closed bug: wontfix)
event.clientX and clientY incorrect for Safari2
| Reported by: | jeffkretz | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.2.2 |
| Component: | event | Version: | 1.2.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
This is factually a bug/incompatibility in Safari, but the event normalization done in jQuery can address this issue.
For IE6, IE7, FF and Safari, on a click event, the clientX and clientY values are relative to the top left of the viewport. For Safari 2, they are relative to the top left of the document.
If you scroll down or to the right, the clientX and clientY for Safari is different from all the other browsers.
Sample page here:
http://www.scorpiontechnology.com/cobalt/mouseclick.htm
One fix would be to add this right after the pageX/Y normalization script under the event.fix method:
// Fix clientX/Y for Safari.
if (jQuery.browser.safari) {
var doc = document.documentElement, body = document.body;
event.clientX = event.clientX - (doc && doc.scrollLeft || body && body.scrollLeft || 0) + (doc.clientLeft || 0);
event.clientY = event.clientY - (doc && doc.scrollTop || body && body.scrollTop || 0) + (doc.clientLeft || 0);
}
This can be seen working on this page:
http://www.scorpiontechnology.com/cobalt/mouseclick_fix.htm
JK
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Correction:
For IE6, IE7, FF and Opera, on a click event ...