Modify ↓
Ticket #445 (closed enhancement: fixed)
normalise pageX/pageY
| Reported by: | sam | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | core | Version: | |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
As Internet Explorer does not support pageX and pageY it would be useful if the properties could still be used. The workaround I use at the moment is:
if(!event.pageX)
{
event.pageX = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
event.pageY = event.clientY + (document.documentElement.scrollTop || document.body.scrollTop);
}
Works with no problems in IE7, Firefox 2 and Opera 8.5.
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.
Note: See
TracTickets for help on using
tickets.

Is there any browser apart from IE that doesn't provide pageX natively?
I'd rewrite the code a little:
if(!event.pageX) { var e = document.documentElement, b = document.body; event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft); event.pageY = event.clientY + (e.scrollTop || b.scrollTop); }