1

I am adding an event listener to a button. In short, in the logic of that function, I want to be able to determine if the click came from a real human click (the default) or if I called it.

So I've got this now:

this.button.addEventListener("click", (e) => 
   {e.stopPropagation()}, true);

And later on, I do this:

this.button.click();

I'd like to able to pass something from my .click() that indicates to the event listener that this was not a manual click from a real user. How can this be done?

I saw several other questions about using this to pass values, but in my case I want to pass the value on function call, not set it to a variable inside the this scope.

Jeremy
  • 5,365
  • 14
  • 51
  • 80
  • 1
    Why don't you just bind a custom event. But if you look at the event object, there is ways to detect it was not trigger by the user. https://stackoverflow.com/questions/14794380/detect-if-button-click-real-user-or-triggered-by-a-script – epascarello Mar 03 '18 at 00:24
  • you could extend your click event with some detail, like described in this answer: https://stackoverflow.com/questions/33989046/is-it-possible-to-re-create-a-onclick-event-using-custom-events-in-javascript – syoels Mar 03 '18 at 00:37

0 Answers0