Well this question has been asked before but in context of jQuery. In jQuery we can check it by originalEvent property of event Object (link) which tells whether its a manual or programmed event.
In my case I am using Javascript Event listeners and triggers. Can we differentiate between the two kind of events (programmed and manual) in this case?
If not then any workarounds?
My Listeners:
function setUpListeners(){
_cellViewWrapper.addEventListener('mousedown',mouseDownHandler,false);
_cellViewWrapper.addEventListener('mouseover',mouseEnter,false);
_cellViewWrapper.addEventListener('blur',blurHandler,true);
_cellViewWrapper.addEventListener('focus',focusEventHandler,true);
}`
Trigger use Cases:
if(!IE_FLAG) hidePicker();
//if browser is internet explorer
else{
//if blur is allowed then hide Picker
if(_ieBlurAllowed) hidePicker();
//if blur is not allowed -- keep focus on picker input
//triggering the focus event here
else blurredElement.focus(); /
}
if((inputElem !== _focussedInput)) setTimeout(function(){ inputElem.focus(); },10);
and many more...
To check if event is triggered by a human with JavaScript, we can use the isTrusted property. 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.
$('button'). click(function(event, wasTriggered) { if (wasTriggered) { alert('triggered in code'); } else { alert('triggered by mouse'); } }); $('button').
event. originalEvent is usually just the native event (also described here). However, if the browser is compatible, and the event was a touch event then that API will be exposed through event. originalEvent . The short answer is that event.
A Trigger is a set of conditions that cause an interaction to run. An event is a user- or administrator-initiated action that an administrator defines that must be met before an interaction is created. Triggers listen for events, and once that event occurs, can initiate an interaction defined within Journey Builder.
In latest browsers, Event.isTrusted is available for this particular use-case. As per its MDN document:
The isTrusted read-only property of the Event interface is a boolean that is true when the event was generated by a user action, and false when the event was created or modified by a script or dispatched via dispatchEvent.
You can simply check inside any event handler:
if (e.isTrusted) {
/* The event is trusted. */
} else {
/* The event is not trusted. */
}
Browser Support: Chrome 46.0, Firefox (latest), Opera 33, Safari & IE (no support)
[Workaround] Javascript: Check if event.screenX
& event.screenY
are non-zero.
var button = document.getElementsByTagName('button')[0];
button.onclick = function(e) {
if(e.screenX && e.screenX != 0 && e.screenY && e.screenY != 0){
alert("real button click");
}
}
When the user clicks on button, it would have some real screenX and screenY based on the button position. But when you do it from code - it would be zero
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With