Jump to content

Logging event coordinates uniformly


Fmdpa

Recommended Posts

I'm working on a click heatmap for analyzing the activity on my website. I began by simply logging clicks using the evt.pageX/evt.pageY properties. But it wasn't long before I found out that varying screen resolutions prevent this from working accurately. How could I log the coordinates of clicks uniformly?

Link to comment
Share on other sites

If your layout is fixed, then you can just use the offsetLeft of your left-most element to get the edge of your layout, then subtract that from the pageX. If it's fluid, well, then the appearance would be different for every resolution anyway.

Link to comment
Share on other sites

Ok, I've got a new problem now. In my script...

window.onclick = function(e) {   y = e.pageY,   x = e.pageX - document.getElementById('container').offsetLeft;   if (x > 0 && y > 0) {	   //ajax stuff   }  }

...it only logs the clicks if they are not on links. How can make it so that when a link is clicked, the click coordinates are logged, then the new page is loaded?

Link to comment
Share on other sites

Hmm... you could always bind the onclick event to the links as well with a synchronous AJAX call, this may slow things down though.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...