Patrick Schomburg Patrick Schomburg - 22 days ago 8
HTML Question

Capture all of the user's mouse clicks on a website

Can i capture a user's mouse click on tags via jquery before the page navigates ? I'd like to send them via an ajax call and record them in a database.

Answer

You can capture any document mousedown or click. Better mousedown perhaps, in order to not be prevented by other click events (via event.preventDefault).

document.onmousedown = function (event) {
  if (!event) {event = window.event;}
  console.log("mousedown "+event.target, event);
  // Post the event object here.
};

With jQuery:

$(document).on('mousedown', function (event) {
  console.log("mousedown "+event.target, event);
  // Post the event object here.
});