0

I'm trying to write some javascript or jquery code to do in order to intercept any type of click inside a website, whether it is performed on a video, a link, image and all the other page elements, basically every type of click (if possible also distinguished between left and right button) on the entire area of the web page and save the coordinate data, the type of the click and address of the page in a db via an ajax call. Has anyone of you an idea of code about it?

Thanks to all

AleMal
  • 1,977
  • 6
  • 24
  • 49
  • 1
    possible duplicate of [How to detect left click anywhere on the document using jQuery?](http://stackoverflow.com/questions/965601/how-to-detect-left-click-anywhere-on-the-document-using-jquery) – Sani Huttunen Aug 18 '14 at 13:56
  • 1
    Regarding plugins that show video (like flash) the document/window/page cannot see those clicks since they are only registered within the plugin. You'd need to add some code to the plugin to accomplish what you want. See http://stackoverflow.com/questions/1444562/javascript-onclick-event-over-flash-object – Sani Huttunen Aug 18 '14 at 13:58

2 Answers2

1

You did not specify what have you tried, with jQuery it's as simple as binding click event to body or document:

$(document).click(function(e){
    //do something here
});

$("body").click(function(e){
    //do something here
});

e parameter from function contains some useful information which you may use: EventObject

Making AJAX is also simple, you have numerous methods, starting with $.post, $.get or $.ajax : jQuery Ajax

kamil
  • 3,482
  • 1
  • 40
  • 64
  • The problem is that clicks on plugin objects like flash will not be registered to the document/window/page. The click will only be visible to the plugin unless the plugin explicitly propagates the click. – Sani Huttunen Aug 18 '14 at 14:02
  • Well, isn't it one of reasons why flash is evil? :) We won't get pass some obstacles unfortunately – kamil Aug 18 '14 at 14:06
1

A basic outline would be:

$('*').on('click', function (e) {
    // make sure the event isn't bubbling
    if (e.target != this) {
        return;
    }
    // do something with the click somewhere
    // for example, make an AJAX request
    $.ajax({
        type: "POST",
        url: "ajaxurl.php",
        data: { x: e.pageX, y: e.pageY }
    })
    .done(function( msg ) {
        alert( "Data Saved: " + msg );
    });
}
Noy
  • 1,258
  • 2
  • 11
  • 28