开发者

Catch/Intercept all mouse clicks

I have this simple script that catches all mouse clicks, unless you click on something that actually works. Links, flash videos, etc. How can I adjust this so no matter what a user clicks on, before the video loads, new page loads, etc. It sends the simple GET request 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();
});


I think the best would be to use live binding and the * selector

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

also the ajax call might need to be synchronous ( you would need to use .ajax() for this.. ) (not sure if this is required though, to avoid the get call being interupted by a normal link click)


Can you not bind the click events to a wildcard? I.E.

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

//do stuff

});

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜