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) ?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
may be we can do something like this:
or a similar approach:
see here:Detect if button click real user or triggered by a script
Note: if you want a jquery solution visit this: Check if event is triggered by a human
You'd probably want to watch for mousemove events and click events. If you're catching click events, but there are no mousemove events, I'd think it's safe to say that robots are clicking on your site.
There is no reliable way to do this just by examining the page events.
You can certainly tell if an event was triggered by code or a "mouse click", however there is no way to know for certain if an actual human clicked the mouse, which I believe is what you're asking.
You could probably watch for mouse movements and analyze them to see if they contain enough artifacts of human muscle movement (non-linear movement), but if this works at all, I wouldn't expect it to last very long until the ad-fraud people catch on and add some randomization.
This is why Google and others have resorted to CAPTCHAs and other Turing-type tests.
You can use vanilla Javascript as in the other anwsers or consider using jquery so you can easily detect non-human clicks.
1.Define a global click event handler using jquery.So you can catch all the clicks on page elements.
2.Check if the event.originalEvent is exists if it exists click was performed by a human. More info
For mouse clicks
For keypress
Here is a sample code.
This is an old question but the accepted answer uses jQuery and I'm sure a lot of visitors here are looking for a vanilla JS solution. If you don't need to support IE, you can use
Event.isTrusted
:https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted
In IE, all events are trusted except those created by
createEvent
:https://technet.microsoft.com/en-us/windows/ff974948(v=vs.60)