webview 中的点击事件不会在被点击的元素上触发

Click events in webview are not firing on the element which was tapped

我们遇到了一个问题,即我们页面中某个元素上的点击事件在与点击的元素不同的元素上触发。这两个元素在页面中是兄弟,因此与事件传播无关。例如,

<div class="a">Element A</div>
<div class="b">Element B</div>

我们将点击处理程序附加到元素 A。但是当我们点击元素 B 时,A 的客户端处理程序将会触发。很难解释为什么会这样,但似乎正在进行某种启发式匹配。

我们还发现,通过跟踪触摸和点击事件,点击的 touchstart 和 touchend 事件在元素 B 上触发,但点击事件在元素 A 上触发。

我们发现问题似乎是由 chromium 中一个名为 "touch adjustment" 的功能引起的。您可以在 chrome://flags:

中查看触摸调整的简短说明

Disable touch adjustment. Windows, Linux, Chrome OS, Android Disables touch adjustment support. Touch adjustment is the process of refining the position of a touch gesture in order to compensate for touches having poor resolution compared to a mouse. #disable-touch-adjustment Enable

似乎当启用触摸调整(默认)时,一个元素上的触摸事件有时会合成为您点击的元素附近的另一个元素上的点击事件。

可以在 chrome://flags 中禁用触摸调整,或者通过传递命令行参数 --disable-touch-adjustment