Sometimes, we want to check if event is triggered by a human with JavaScript.
In this article, we’ll look at how to check if event is triggered by a human with JavaScript.
How to check if event is triggered by a human with JavaScript?
To check if event is triggered by a human with JavaScript, we can use the isTrusted property.
For instance, we write
if (e.isTrusted) {
// ...
} else {
// ...
}
to check if the event is triggered by a human in our event handler callback.
e is the event object and it had the isTrusted property.
If isTrusted is true, then the event is triggered by a human.
Conclusion
To check if event is triggered by a human with JavaScript, we can use the isTrusted property.