Search code examples
javascriptcontextmenu

Show contextmenu only after long press


I want to activate a context-menu only after left-mousedown is pressed for N seconds (e.g. 2 seconds).
If the mouse is released, the context-menu should not be shown.
I tried to use:

  • setTimeout and clearTimeout - to handle the wait time.
  • jquery contextmenu - for using the context-menu.

But I cannot get the expected behaviour.
What I get is a delay before showing the context-menu for the first time, but:

  • if I stop pressing the mouse before the wait time, the context-menu still shows up.
  • after the first time, the context-menu is shown with every click, even is the mouse is released before the wait time.

How can I condition showing the context-menu, only after the mouse is clicked for a specified time period?

Thanks


Solution

  • I ended up using the solution in here. It uses the methods:

    Window.setTimeout, Window.clearTimeout,