JavaScript gets the coordinates of the mouse when moving (compatible with: IE8, Google, Firefox, Opera), and passes the test
Copy it directly into an html file and run it.
To facilitate everyone's test, an online demonstration was prepared
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JavaScript gets the coordinates when the mouse moves (compatible: IE8, Google, Firefox, Opera)_Wulin.com</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <style type="text/css"> .tip { width:200px; border:2px solid #ddd; padding:8px; background:#f1f1f1; color:#666; } </style> <script type="text/javascript"> //Method 1 function mousePos(e){ var x,y; var e = e||window.event; return { x:e.clientX+document.body.scrollLeft + document.documentElement.scrollLeft, y:e.clientY+document.body.scrollTop + document.documentElement.scrollTop }; }; //Method 2 //Firefox supports attributes pageX and pageY properties. These two properties have included page scrolling. //In Chrome, the page scrolling displacement can be calculated through document.body.scrollLeft, document.body.scrollTop, and under IE, you can use document.documentElement.scrollLeft, document.documentElement.scrollTop function getMousePos(event) { var e = event || window.event; var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; var scrollY = document.documentElement.scrollTop || document.body.scrollTop; var x = e.pageX || e.clientX + scrollX; var y = e.pageY || e.clientY + scrollY; //alert('x: ' + x + '/ny: ' + y); return { 'x': x, 'y': y }; } function test(e){ document.getElementById("mjs").innerHTML = getMousePos(e).x+','+getMousePos(e).y; }; </script> </head> <body> <div id="mjs">Get the mouse click position coordinate</div> <div id="test" onmousemove="test(event)"></div> </body> </html>