Is it possible to set the location / position of the mouse cursor on a document loading event. (in javascript)

Just wondering if you can get the x / y location of the mouse from the onload event of the document (before any mousemove events).

thanks

Guido

+4
source share
2 answers

short answer: no

long answer: yes. the onload event does not provide information about the position of the mouse, however, you can set the variable when running onload and use the onmousemove event in the document to get the mouse pointer immediately after moving the mouse after loading documents (after the variable was set). Not what you wanted.

+3
source

You can try something like:

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> <script type="text/javascript"> function SetValues() { var IE = document.all?true:false; if (!IE) document.captureEvents(Event.MOUSEMOVE) getMouseXY(); var mX = 0; var mY = 0; function getMouseXY(e) { if (IE) { mX = event.clientX + document.body.scrollLeft; mY = event.clientY + document.body.scrollTop; } else { mX = e.pageX; mY = e.pageY; } var s = 'X=' + mX + ' Y=' + mY ; document.getElementById('divCoord').innerHTML = s; return true; } } </script></head> <body onload=SetValues()> <div id="divCoord"></div> </body></html> 
+1
source

Source: https://habr.com/ru/post/1301061/


All Articles