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:
contextmenu
event:
touchstart contextmenu touchendNote that Chrome vibrates at the same time
contextmenu
is fired.
touchstart contextmenu touchcancelFirefox cancels the touch event as soon as
contextmenu
is fired, which is a problem for me.
touchstart contextmenu touchendNice. It dosen't vibrate.
contextmenu
event:
touchstart contextmenu touchendIt vibrates and scrolls, however.
touchstart contextmenu touchcancelAgain, it's canceling the touch, but no text is selected.
touchstart contextmenu touchendAnd still vibrates and scrolls.
touchstart contextmenu touchcancelSame thing :(
So, is there any way to prevent scrolling, context menus, vibration and selecting text, and to avoid Firefox canceling the touch?
Fixed in future firefox mobile browsers: https://bugzilla.mozilla.org/show_bug.cgi?id=1481923