Catch / intercept all mouse clicks

I have this simple script that catches all mouse clicks unless you click on something that really works. Links, flash movies, etc. How can I configure it this way, no matter what the user clicks, before downloading a video, loading new pages, etc. Does it send a simple GET request that I built?

(function($) { 

$.fn.saveClicks = function() { 
$(this).bind('mousedown.clickmap', function(evt) {
    var clickDocument = (document.documentElement != undefined && document.documentElement.clientHeight != 0) ? document.documentElement : document.body;
    var width = clickHeatDocument.clientWidth != undefined ? clickDocument.clientWidth : window.innerWidth;
    var height = clickHeatDocument.clientHeight != undefined ? clickDocument.clientHeight : window.innerHeight;
    var scrollx = window.pageXOffset == undefined ? clickDocument.scrollLeft : window.pageXOffset;
    var scrolly = window.pageYOffset == undefined ? clickDocument.scrollTop : window.pageYOffset;
    var x = evt.clientX + scrollx;
    var y = evt.clientY + scrolly;
    $.get('/click-save.php', {  
        "x":x,  
        "y":y,
        "click":"true",
        "w":width,
        "h":height,
        "l":escape(document.location.pathname),
        "d":escape(document.domain)
    }); 
}); 
};

})(jQuery); 

$(function() {
    $(document).saveClicks();
});
+3
source share
2 answers

I think it would be best to use direct binding and a * selector

$('*').live('click.clickmap', function(evt){ ... });

you may also need a synchronous ajax call (you need to use .ajax()for this ..) (not sure if this is required, though, to avoid intercepting a call caused by clicking a regular link)

+2
source

click ? .

$('*').bind('mousedown.clickmap', function(evt){

//do stuff

});

+1

Source: https://habr.com/ru/post/1750368/


All Articles