Chrome 和 Firefox for Android 中长按的奇怪行为 [英] Weird behavior of long presses in Chrome and Firefox for Android

查看:43
本文介绍了Chrome 和 Firefox for Android 中长按的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在 Chrome 和 Firefox for Android 中发现了一些奇怪的长按行为.我试图避免滚动、上下文菜单、振动和选择文本.另外,我需要不要取消触摸.我设置了这样一个简单的页面:

So, I found some weird behavior of long presses in Chrome and Firefox for Android. I'm trying to avoid scrolling, context menus, vibration and selecting text. Also, I need the touch not to be canceled. I set a simple page like this:

var logger = document.getElementById("logger")

function touchHandler(e) {
  e.preventDefault()
  logger.innerText += e.type + "\n"
}
function contextMenuHandler(e) {
  e.preventDefault()
  logger.innerText += e.type + "\n"
}

window.addEventListener("touchstart", touchHandler)
window.addEventListener("touchmove", touchHandler)
window.addEventListener("touchend", touchHandler)
window.addEventListener("touchcancel", touchHandler)
window.addEventListener("contextmenu", contextMenuHandler)

<pre id="logger"></pre>

我得到了这些结果,在不移动手指的情况下按一下:

And I got these results, when pressing for a bit without moving the finger:

  1. 当我默认阻止触摸事件和 contextmenu 事件时:
    • Chrome 日志:
  1. When I default prevent both touch events and the contextmenu event:
    • Chrome logs:
touchstart
contextmenu
touchend

请注意,Chrome 会在触发 contextmenu 的同时振动.

  • Firefox 日志:

    Note that Chrome vibrates at the same time contextmenu is fired.

  • Firefox logs:

    touchstart
    contextmenu
    touchcancel

    Firefox 会在 contextmenu 被触发后立即取消触摸事件,这对我来说是个问题.

  • Firefox cancels the touch event as soon as contextmenu is fired, which is a problem for me.

    • Chrome 日志:
    • Chrome logs:
    touchstart
    contextmenu
    touchend

    好的.它不振动.

  • Firefox 记录了同样的事情.这一次,它没有取消触摸,而是选择了一些文本.
    • 当我默认只阻止 contextmenu 事件时:
    • Chrome 日志:
      When I default prevent only the contextmenu event:
    • Chrome logs:
    touchstart
    contextmenu
    touchend

    然而,它会振动和滚动.

  • Firefox 日志:

    It vibrates and scrolls, however.

  • Firefox logs:

    touchstart
    contextmenu
    touchcancel

    同样,它取消了触摸,但没有选择文本.

  • Again, it's canceling the touch, but no text is selected.

    • Chrome 日志:
    • Chrome logs:
    touchstart
    contextmenu
    touchend

    并且仍然振动和滚动.

  • Firefox 日志:

    And still vibrates and scrolls.

  • Firefox logs:

    touchstart
    contextmenu
    touchcancel

    一样 :(

  • 那么,有什么办法可以防止滚动、上下文菜单、振动和选择文本,并避免 Firefox 取消触摸?

    So, is there any way to prevent scrolling, context menus, vibration and selecting text, and to avoid Firefox canceling the touch?

    推荐答案

    在未来的 firefox 移动浏览器中修复:https://bugzilla.mozilla.org/show_bug.cgi?id=1481923

    Fixed in future firefox mobile browsers: https://bugzilla.mozilla.org/show_bug.cgi?id=1481923

    这篇关于Chrome 和 Firefox for Android 中长按的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆