PageX pageY does not work in IE8 if I add <! DOCTYPE html>
Hi guys, I have the following script that gives me the cursor position when I move the mouse. this script works fine in chrome, FF and even in IE 8 (without ! doctype html )
if you add ! DOCTYPE html to html page. it gives me an object, does not support this property error. and the line below causes the problem
document.captureEvents (Event.MOUSEMOVE);
How can I fix this problem with ! DOCTYPE html included in IE 8.
window.onload = init; function init() { if (window.Event) { document.captureEvents(Event.MOUSEMOVE); } document.onmousemove = getCursorXY; } function getCursorXY(e) { document.getElementById('cursorX').value = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); document.getElementById('cursorY').value = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); } I assume you are getting an error because <!DOCTYPE html> is an ad for HTML5 and IE 8 will not be able to handle HTML5.
Have you decided to switch to jQuery? It will have all the functions necessary to achieve the same.
Yes, not supported for IE9-. You can check these compatibility issues at this link. http://quirksmode.org/compatibility.html
Use the IE DOM event equivalent to the W3C DOM event:
W3C DOM IE DOM clientX (pageX - pageXOffset) clientY (pageY - pageYOffset) offsetX pageXOffset offsetY pageYOffset
And switch using lazy evaluation with W3C as the default API:
clientX || (pageX - pageXOffset); References