I’m helping to debug a website and sometimes i get this error :
Object required on CWS.js line 45 character 3
// Track cursor position
var CWS_curPosX, CWS_curPosY;
document.onmousemove = CWS_MouseMove;
function CWS_MouseMove(evt)
{
if(window.Event)
{
if(evt && evt.pageX)
{
CWS_curPosX = evt.pageX;
CWS_curPosY = evt.pageY;
}
}
else
{
CWS_curPosX = event.clientX + document.body.scrollLeft; // line 45
CWS_curPosY = event.clientY + document.body.scrollTop;
}
I have no idea to solve this…
Thanks in advance.
There is a couple of crucial isues with your code, primarily your use of
window.Event– thisif(...)condition will always evaluate false, as no browser supports this property on thewindowobject. In actual fact the property has a lower caseein IE.So this construct is often used, and looks similar to yours:
Read this link (event object in different browsers) for more info.
This cross-browser difference is one of many reasons many people tend to use a framework such as jQuery which simplifies this event-handling code into one unified method of reading properties of the event.