views:

27

answers:

2

how do i determine the mouse location on an image using javascript when mouse is clicked

+1  A: 

trimmed version of the solution linked by geeketteSpeaks:

<html>
<head>
<script type="text/javascript">
    function getImageCoords(event,img) {
        var posX = event.offsetX?(event.offsetX):event.pageX-img.offsetLeft;
        var posY = event.offsetY?(event.offsetY):event.pageY-img.offsetTop;
        alert("You clicked at: ("+posX+","+posY+")");
    }
</script>
</head>
<body>
    <img src="image.jpg" onclick="getImageCoords(event,this);">
</body>
</html>
jnpcl