What's the simplest way to add a click event handler to a canvas element that will return the x and y coordinates of the click (relative to the canvas element)?
No legacy browser compatibility required, Safari, Opera and Firefox will do.
Update: Thanks @Brian, the following is working (in Opera and FF3 at least):
canvas.addEventListener("click",
function(e) {
alert("x:"+(e.clientX-canvas.offsetLeft)
+" y:"+(e.clientY-canvas.offsetTop));
}, false);
Update: Note, don't forget to call removeEventListener()
if the above code is called more than once or the click handler will be called multiple times...