Search code examples
javascriptmobile-browser

Context menu event hiding mouse up on android


I have an image and I need to measure how long user touch the image or has mouse pressed on the image. So I use mouse down event to to get the start time and mouse up event to get the finish time. However, when running on android device, the long touch triggers the context menu to pop up, which I don't want. I can hide the context menu by adding function on context menu event and return false from it. The context menu is blocked and not displayed. BUT the mouse up event does not triggered either.

How to block context menu and still have mouse up event?

Jsfiddle [here][1]

  [1]: https://jsfiddle.net/vghk9q53/5/

Solution

  • Instead of using mousedown and mouseup you should use touchstart and touchend