Stephen Chalmers wrote :
// It's best to monitor mouse co-ordinates with a dedicated handler:
var mouseX, mouseY;
function getMousePos(e)
{
if (!e)
var e = window.event||window.Event;
This manner of coding is not recommendable, IMO. In javascript strict
mode (reporting warnings), Firefox will report that "variable e hides
argument". This manner of coding just makes debugging more difficult.
I recommend
var TheEventObject;
if(e)
{
TheEventObject = e;
}
else if(window.event)
{
TheEventObject = window.event;
}
else
{
TheEventObject = null;
};
if('undefined'!=typeof e.pageX)
{
mouseX = e.pageX;
mouseY = e.pageY;
}
else
{
mouseX = e.clientX + document.body.scrollLeft;
This will work in MSIE 5 but what if the document triggers standards
compliant mode in MSIE 6? In such case, the provided code will not
succeed as the root element is not the same.
As written, the code [indirectly] is not promoting web standards. As
written, the code is more backward-compatible than forward-compatible.
mouseY = e.clientY + document.body.scrollTop;
}
}
// You need to tell Mozilla to start listening:
if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEMOVE);
Why not register the listener to the object with DOM 2 Events method?
It's forward-compatible. Future-proof.
Gérard