捕获/拦截所有鼠标单击 [英] Catch/Intercept all mouse clicks

查看:58
本文介绍了捕获/拦截所有鼠标单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的脚本,可以捕获所有鼠标单击,除非您单击实际起作用的东西.链接,Flash视频等.在视频加载,新页面加载等之前,无论用户单击什么,如何进行调整?它都会发送我构建的简单GET请求?

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){ ... });

也可能需要同步ajax调用(为此您需要使用.ajax().)(不确定是否需要这样做,以避免正常链接中断get调用. )

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)

这篇关于捕获/拦截所有鼠标单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆