onblur event not working with google chrome

后端 未结 3 1984
你的背包
你的背包 2021-01-01 03:27

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 mistak

相关标签:
3条回答
  • 2021-01-01 03:46

    Just ran into this issue...

    onBlur (with a capital "B") doesn't work, but onblur (lowercase "b") does. Go figure! ;-/

    0 讨论(0)
  • 2021-01-01 03:50

    Chrome accepts OnBlur event. what i have experience is... on check or uncheck of checkbox, chrome do not focus on it.

    Add attribute

    onclick="this.focus()" onblur="yourMethod()"/>
    

    you will see it work fine then.

    0 讨论(0)
  • 2021-01-01 04:01

    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>
    
    0 讨论(0)
提交回复
热议问题