S
S
Sergey Sokolov2019-02-15 13:11:56
JavaScript
Sergey Sokolov, 2019-02-15 13:11:56

How to determine if a function is called by a user action or not?

Events have a read-only isTrusted property that indicates, for example, whether it was a real mouse click or just triggered this event on an element.
Popup windows are only opened if they are reached by a call chain initiated by a user action, a click.
How is it possible inside any function, without accessing the property of the original event, to find out whether it is now legal to open a new window? Maybe there are some properties/methods of the current context/environment?
Perhaps you can try to create a new window and check the result. But I wonder if it is possible somehow else - is there an analogue of the isTrusted property somewhere in the context?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2019-02-15
@nyakove

You can store the value of isTrusted in a variable that is visible from the function and see if it was a real click or not

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question