Detecting double right-click

You can use the .detail property of a mouse event object to see if an event was the second click in a short period of time, allowing you to detect a double right-click. Unfortunately jQuery strips the .detail property when it wraps event objects so you have to access it via the .originalEvent property.

by UselessCode

HTML

<div id="target">Right click me!</div>

CSS

#target {
    height: 100px;
    width: 100px;
    background: #ff0;
}

JavaScript

// suppress the right-click menu
$('#target').on('contextmenu', function (evt) {
    evt.preventDefault();
});

$('#target').mouseup(function (evt) {
  if (evt.which === 3) { // right-click
    /* if you wanted to be less strict about what
       counts as a double click you could use
       evt.originalEvent.detail > 1 instead */
    if (evt.originalEvent.detail === 2) { 
      $(this).text('Double right-click');
    } else if (evt.originalEvent.detail === 1) { 
      $(this).text('Single right-click');
    }
  }
});