Event object's pageX and pageY are still broken

Event object's pageX and pageY are still broken


Hi,
I'm currently working on a wysiwyg editor program, so I have scripts
accessing elements inside the iframe from the parent page. I bound
some events to document object for the iframe page. When the events
were fired, I couldn't get the right pageX and pageY. Then I looked up
into the source code, and found jquery's code to compute pageX and
pageY for IE:
        // Calculate pageX/Y if missing and clientX/Y available
        if ( event.pageX == null && event.clientX != null ) {
            var e = document.documentElement, b = document.body;
            event.pageX = event.clientX + (e && e.scrollLeft || b.scrollLeft ||
0);
            event.pageY = event.clientY + (e && e.scrollTop || b.scrollTop ||
0);
        }
Seems nice, but notice that my scripts were running in the parent
page, which means that maybe the document object is in fact not the
document inside the iframe, but its parent page's. Is that true? At
least I think so.
If my understanding is right, then maybe the codes should be modified
like this:
        // Calculate pageX/Y if missing and clientX/Y available
        if ( event.pageX == null && event.clientX != null ) {
var owenerDocument =
event.target.ownerDocument || event.target;
            var e = owenerDocument.documentElement, b = owenerDocument.body;
            event.pageX = event.clientX + (e && e.scrollLeft || b.scrollLeft ||
0);
            event.pageY = event.clientY + (e && e.scrollTop || b.scrollTop ||
0);
        }
I haven't tested it throughly. If there's something wrong, please tell
me, thanks.