Return to Snippet

Revision: 34385
at October 22, 2010 01:03 by juanduke


Initial Code
<!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>

Initial URL

                                

Initial Description
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

Initial Title
position div with mouse coords (onClick event)

Initial Tags
javascript, html, ie6

Initial Language
JavaScript