检测网页上的综合点击次数 [英] Detect synthetic clicks on a webpage

查看:173
本文介绍了检测网页上的综合点击次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Javascript可以检测到合成点击(不是人造成的点击,而是使用JS或其他自动化工具生成的)?

Through Javascript is it possible to detect synthetic clicks (the clicks that were not generated by human but instead was generated using JS or some other automation tool) ?

推荐答案

您可以在其他浏览器中使用香草JavaScript,或者考虑使用jquery,以便您轻松检测非人类点击。

You can use vanilla Javascript as in the other anwsers or consider using jquery so you can easily detect non-human clicks.

1。使用jquery定义全局点击事件处理程序,您可以捕获页面元素的所有点击。

1.Define a global click event handler using jquery.So you can catch all the clicks on page elements.

 $(document).click(function(event) {
  });

2.检查event.originalEvent是否存在,如果存在点击是由人执行的。
更多信息

2.Check if the event.originalEvent is exists if it exists click was performed by a human. More info

对于鼠标点击

 $(document).click(function(event) {
    if (event.originalEvent === undefined) {
        alert('not human')
    } else {
        alert(' human');
    }
 });

对于按键

$(document).keypress(function(event) {

    if (event.originalEvent === undefined) {
        alert('not human')
    } else {
        alert(' human');
    }
});

以下是示例代码。

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
 $(document).click(function(event) {
    if (event.originalEvent === undefined) {
        alert('not human')
    } else {
        alert(' human');
    }
});
$(document).keypress(function(event) {

    if (event.originalEvent === undefined) {
        alert('not human')
    } else {
        alert(' human');
    }
});
   $(document).click();
   $(document).keypress();
});
</script>
</head>
<body>
<p>Click me !</p>
</body>
</html>

这篇关于检测网页上的综合点击次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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