Defining actions for left and right buttons on mousedown

I am using mousedown to execute audio files on a soundboard… this works on left, middle, and right buttons.

I am using the following code to execute a cancel function when the right button is used:

$(document).ready(function(){ 
  document.oncontextmenu = function() {return false;};

  $(document).mousedown(function(e){ 
    if( e.which == 3 ) { 
      Cancel_playback();
      return false; 
    } 
    return true; 
  }); 
});

This works… except that if a right-click is executed over one of the audio buttons, it still counts as a mousedown and sends both the cancel command, as well as the playback function.

Is there a way to make it NOT do the default action and ONLY do the Cancel_Playback on a right-click?

In any event handler, you have access to the event object (aliased to e in your mousedown function). That object can prevent default actions. Here’s how:

$(document).mousedown(function(e){ 
    e.preventDefault();
    if( e.which == 3 ) { 
      Cancel_playback();
      return false; 
    } 
    return true;
});

Don’t you want to have the preventDefault inside the if statement? So that you’ll still be able to have the default if it bubbles.

Hmmmmm… tried as shown and tried with it inside the if statement… but the right-click is still performing the normal mousedown action.

Would its position in the js file have anything to do with anything?

Ok… so the problem with the preventDefault is that I am not trying to prevent any default behavior. The mousedown events that I am trying to block on right-mousedown are other functions.

So I guess what I am looking for is a way to say when e.which == 3, don’t do these functions but do this function instead…

fiddle.net/g9sh1dme/15/

Might give a better idea of what I am trying to do…