JSFiddle: http://jsfiddle.net/6WMXh/170/
I have a canvas with a snowy effect overlaying the web page, and I want to delegate clicks through the canvas to the element beneath which was meant to be clicked.
This script works for other objects, but fails on the image map (with AREA tags) in certain browsers.
Works: IE10, Chrome;
Fails: FF, Safari.
// delegate click through canvas to page
canvas.addEventListener('click', function(event) {
event = event || window.event;
canvas.style.zIndex = "0";
target = document.elementFromPoint(event.clientX, event.clientY);
if (target.click) {
target.click();
} else {
target.onclick();
}
canvas.style.zIndex = "1000000";
}, false);
Please see the JSFiddle for a demonstration of the problem. When you click on the map which is not overlapped by the Canvas the AREA element's onclick function fires. However, when you click on the part of the Map covered by the Canvas it does not fire the onclick function in the specified browsers. Try the JSFiddle with IE10/Chrome: there isn't a problem, try it with FireFox/Safari to see the problem.
What's going wrong?