Sure, just find out the top left corner coords of the image, use clientX and clientY in window.event (IE) and pageX and pageY in the event that standards-complient browsers gives the function executed by the event. Something like this:
Code:
<html>
<head>
<script type="text/javascript">
window.onload = function()
{
document.getElementById( 'myimage' ).onclick = getClickedCoords;
}
function getClickedCoords( e )
{
var x = e.pageX || window.event.clientX;
var y = e.pageY || window.event.clientY;
var img = document.getElementById( 'myimage' );
x = x - parseInt( img.style.left, 10 );
y = y - parseInt( img.style.top, 10 );
alert( 'x: '+ x +', y: '+ y );
}
</script>
</head>
<body>
<img src="image.jpg" style="position: absolute;left:100px;top:100px;" id="myimage">
</body>
</html>
Bookmarks