onblur event not working with google chrome

kiran picture kiran · Mar 9, 2010 · Viewed 19.1k times · Source

I am trying to use onblur event to close a window. Its working fine in IE, Firefox and safari, but the event does not trigger in chrome. is that a bug in chrome or a mistake from me

Answer

jkoreska picture jkoreska · Jun 3, 2011

I realize this was over a year ago, but it showed up for me in Google while trying to solve this same issue.

It seems Chrome does not consider some elements, like body and anchors, to be "focusable". According to the following page, you can make any element focusable (thereby activating the blur event) by setting the tabindex attribute: http://www.quirksmode.org/dom/events/blurfocus.html

Like so:

<a href="#" tabindex="0" onblur="alert('blur')"> blur me </a>