是否有任何方法可以让我检测按钮点击是由真实用户执行的,而不是用户加载到其浏览器开发者的一些自动方法(javascript)控制台或其他浏览器开发工具?检测按钮是否点击真实用户或由脚本触发
我尝试了以下方法建议在各种计算器的帖子,但他们都没有出现工作。 REF:How to detect if a click() is a mouse click or triggered by some code?
脚本检测方法尝试和失败:
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浏览器控制台上面这些都不是陷阱它的方法,按一下按钮作为被一个触发脚本。
var button = document.getElementById("btnSubmit");
button.click();
=========================================== ===============================
谢谢你所有的回复,并感谢提供这样一个伟大的计算器该网站有助于实现这么多的知识共享,并为我们节省了无数个小时的技术人员。
看来我还没有可靠的方法。所有3种浏览器(FF,IE & Chrome)均为用户提供开发者/控制台界面,以在我的网页上运行/注入JavaScript。看起来,每个浏览器的味道都会稍微区别一些事件属性值。例如:Chrome将脚本激活的cick和真实用户之间的差异用e.screenX捕捉,但在IE中:e.screenX对脚本单击(合成)和用户按钮单击具有相同的值点击
以下检测方法根本不起作用或在不同浏览器中不一致:e.isTrsuted e.originalEvent(event.source!= window)(e.distance!= null)
mousedown事件显示为只能由一个真正的用户按钮点击触发,但我必须假设除了点击按钮事件之外,还有一些脚本方法来模拟mousedown。 (五){alert('mouseisdown真正的按钮点击'); }
如果任何人都可以找出一种在多个浏览器上工作的可靠方法,它可以检测合成(脚本)按钮点击和用户点击按钮之间的区别,您将拥有超级英雄状态。
截至目前,我看不到一个公认的答案。更糟糕的是,我不会接受。 – 2016-01-21 16:28:36
对于firefox e.isTrusted的作品,不知道别人。 ** e.isTrsuted **不起作用;-) – 2016-02-07 15:34:27