Skip to content Skip to sidebar Skip to footer

Strange Click Event Bubble On Iphone Safari That It Stop Before Bubbling To Document.body

I have bind a click event as document.body.onclick = function(){alert('aaa')}; It do good both on android or chrome on IOS whatever element I click. But it does not trigger on iPho

Solution 1:

I know this is quite old, but I still managed to dig it up when I ran into the very same issue.

In short, mouse events in iOS Safari do not bubble up to the document.body unless iOS Safari thinks the event target is a clickable element.

Clickable element is one of the following:

  1. The target element of the event is a link or a form field.

  2. The target element, or any of its ancestors up to but not including the <body>, has an explicit event handler set for any of the mouse events. This event handler may be an empty function.

  3. The target element, or any of its ancestors up to and including the document has a cursor: pointer CSS declarations.

(Quoted from here, emphasis mine.)

Possible fixes include:

  • Add cursor: pointer to any element that does not fit the description.
  • Add a no-op event handler to the target.
  • Handle the clicks one level below document.body.

Post a Comment for "Strange Click Event Bubble On Iphone Safari That It Stop Before Bubbling To Document.body"