简体   繁体   中英

How to determine what triggered a blur

I have a button on an AngularJS page that has numerous directives, and when tabbing to the button after a second or so it blurs. I can stop the blur event itself by adding an ng-blur and issuing a preventDefault(), but I'd like to be able to filter out when to preventDefault based on the cause of the blur. Is there any way to find out what the original source of the blur was?

Within the blur event handler I did a JQuery for (':focus') and it's empty, so that doesn't help for identification purposes. I also didn't find anything useful in the $event object passed into the event handler.

Also, the problem is exclusive to MS Edge, sorry for omitting this originally.

Any ideas?

Thanks,

Matt

After the button loses focus, you can call:

document.activeElement

to see which element the browser has given focus.

As for what is causing the blur, you'll need to post your code so we can look at it or debug/properly step through your code.

Check event.relatedTarget

It is experimental feature, but widely supported.

Not really an answer other stating I couldn't find an actual way to programmatically determine the blur trigger, but I found the triggering event which was caused by someone using browser detection and assuming Chrome in the UA meant it was definitively Chrome.

Thanks for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM