Given a button reference, you can use javascript on your console to .click()
it.
Is there a way for my website to differentiate between a click triggered by a mouse and a click triggered by the user's javascript? Or are these effectively equivalent from the browser's point of view?
CodePudding user response:
Use Event.isTrusted
Yes, you can use the event.isTrusted
property. Will be true when the user clicks as shown in this code snippet.
mybutton.addEventListener("click", function(e) {
console.log( "isTrusted = " e.isTrusted );
});
test.addEventListener("click", function(e) {
mybutton.click();
});
<button id="mybutton">My Button</button>
<button id="test">Test</button>