检测是否按一下按钮真实用户或一个脚本触发 [英] Detect if button click real user or triggered by a script

查看:176
本文介绍了检测是否按一下按钮真实用户或一个脚本触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有使我能够检测点击一个按钮是否由实际用户进行的,而不是一些自动化的方法(JavaScript)的用户已加载到自己的浏览器开发者控制台或其他浏览器开发人员工具的任何方法?

Is there any method that enables me to detect whether a button click was performed by a real user and not some automated method (javascript) that a user has loaded onto their browser developer console or other browser developer tool?

我尝试以下方法,在不同的岗位计算器建议,但没有人似乎工作。
REF:<一href=\"http://stackoverflow.com/questions/7635274/how-to-detect-if-a-click-is-a-mouse-click-or-triggered-by-some-$c$c\">How检测一个点击()是一个鼠标点击或一些code触发?

I tried the following methods suggested in various stackoverflow posts but none of them appear to work. REF: How to detect if a click() is a mouse click or triggered by some code?

脚本检测方法尝试和失败:

Script Detection methods tried and failed:

mybutton.click(function (e) {
    if (!e.which) {
        //Triggered by code NOT Actually clicked
        alert(' e.which - not a real button click')
    } else if ('isTrusted' in e && !e.isTrsuted) {
        //Triggered by code NOT Actually clicked
        alert(' e.isTrusted - not a real button click')
    } else if (e.originalEvent === undefined) {
        //Triggered by code NOT Actually clicked
        alert(' e.originalEvent - not a realbutton click')
    }
    //                  else if (!e.focus) {
    //                      //triggered  // does not detect e.focus on a real btn click
    //                      alert(' e.focus - not a realbutton click')
    //                  }
    else {
        // Button hopefully clicked by a real user and not a script
    }
})

如果我运行下面的脚本触发从Chrome浏览器控制台都不上述方法捕获它作为一个脚本触发,按一下按钮

If I run the following script to trigger the button click from the Chrome browser console none of the methods above traps it as being triggered by a script.

var button = document.getElementById("btnSubmit");
button.click();

=============================================== ===========================

==========================================================================

感谢您为您的所有答复和感谢StackOverflow的提供有助于这么多知识共享这样一个伟大的网站,并救了我们技术人员的小时无数。

Thank you for all your responses and thanks to stackoverflow for providing such a great site that facilitates so much knowledge sharing and for saving us techies an untold number of hours.

看来,我还没有可靠的方法。所有3浏览器(FF,IE浏览器和放大器; Chrome浏览器),用于用户运行/在我的网页注入一个javascript提供了一个开发者/控制台接口。看来,每个浏览器的味道陷阱一些事件属性不同值一点点。例如:镀铬陷阱脚本启动依次点击和e.screenX但在IE实际用户之间的区别:e.screenX具有相同的价值为脚本点击(合成)和一个用户点击按钮

It appears that I still do not have reliable method. All 3 browsers (FF, IE & Chrome) provide a developer/console interfaces for a user to run/inject a javascript on my webpage. It appears that each browser flavor traps some event property values a little differently. For example: Chrome traps the difference between a script activated cick and a real user with e.screenX but in IE: e.screenX has the same value for both a script click (synthetic) and a user button click

下面的检测方法或者根本不工作或在不同的浏览器不一致:e.which e.​​isTrsuted e.originalEvent(!event.source =窗口)(!e.distance = NULL)

The following detection methods either did not work at all or are inconsistent across the different browsers: e.which e.isTrsuted e.originalEvent (event.source != window) (e.distance != null)

MouseDown事件似乎是由一个真实的用户点击按钮只能触发,但我必须假设有一些脚本方法除了一个按钮单击事件来模拟鼠标按下

The mousedown event appears to be only triggered by a real user button click, but I have to assume there is some script method to emulate a mousedown in addition to a button click event

$(me.container +'.mybutton')鼠标按下(功能(E){警报('mouseisdown真正的按钮点击');}

$(me.container + ' .mybutton').mousedown(function (e) { alert('mouseisdown real button click'); }

如果任何人都可以弄清楚,在多个浏览器上运行的可靠方法,即由用户检测到合成(脚本)按钮,点击一个按钮,点击之间的差异,你会值得超级英雄的地位。

If anyone can figure out a reliable method that works across multiple browsers, that detects the difference between a synthetic (script) button click and a button click by a user, you will deserve superhero status.

推荐答案

在点击一个按钮功能就是通过鼠标,事件E通常有记录鼠标指针位置。尝试是这样的:

when a button click happens through the mouse, the event e usually has the mouse pointer location recorded. Try something like :

   if(e.screenX && e.screenX != 0 && e.screenY && e.screenY != 0){
     alert("real button click");
   }

这篇关于检测是否按一下按钮真实用户或一个脚本触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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