/ Published in: JavaScript
On click event, display a div on mouse coords.
Tested on Firefox 3.6.11, chrome 6, internet explorer 6.
Based on this source code: http://www.webdeveloper.com/forum/showthread.php?t=92007
Tested on Firefox 3.6.11, chrome 6, internet explorer 6.
Based on this source code: http://www.webdeveloper.com/forum/showthread.php?t=92007
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Aratti@py</title> <script language="JavaScript" type="text/JavaScript"> function checkS(e){ // capture the mouse position var posx = 0; var posy = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; } else if (e.clientX || e.clientY) { posx = e.clientX; posy = e.clientY; } document.getElementById('pos').innerHTML = 'Mouse position is: X='+posx+' Y='+posy; document.getElementById('pos').style.left = posx; document.getElementById('pos').style.top = posy; document.getElementById('pos').style.display='block'; } </script> </head> <body onClick="checkS(event)"> <div id="pos" style="position:absolute; display:none;">test</div> </body> </html>