Why is blur event not fired in iOS Safari Mobile (iPhone / iPad)?

后端 未结 5 1198
感动是毒
感动是毒 2020-12-15 17:46

I\'ve two event handlers bound to an anchor tag: one for focus and blur.

The handlers fire on desktop, but in iphone and ipad only focus is fired correctly. Blur is

5条回答
  •  既然无缘
    2020-12-15 18:24

    I have check all the doc in the @NicholasShanks answer, but a little frustrated testing all the events.

    Android and iOS:

    • Tested on Android Samsung S9
    • Tested on iOS iPad 5ºgen

    Finally i have got a solution: Seems iPad listen to mouseout as blur, and seems android listen perfectly to the blur event, i just add a ternary on this case to attach the right event (previously i have aimed to a mobile or tablet device instead of a computer.

    // element >> element you want to trigger
    // os >> function that return operative system 'ios' or 'android' in my case
    
    element.addEventListener(os === 'ios' ? 'mouseout' : 'blur', () => {
      // Do something
    })
    

提交回复
热议问题