javascript - prevent previously defined events on mousedown for right-click only -


i have soundboard buttons trigger ajax posts on mousedown.

the ideal functionality play audio on left-mousedown , cancel playback on right-mousedown.

the code have far disables context menu , cancels playback...however, if on button when right-click (that triggers other defined events), still honor mousedown , play audio.

$(document).ready(function(){    document.oncontextmenu = function() {return false;};   $(document).mousedown(function(e){      if( e.which == 3 ) {         e.preventdefault();         cancel_playback();       return false;      }      return true;    });  }); 

i trying disable right-mousedown triggering defined events honor cancel_playback. ideas?

edit updated title , description more accurately reflect trying accomplish. should help: http://jsfiddle.net/g9sh1dme/15/

stopimmediatepropagation function you're looking for.

it cancels other events bound the same element , other delegates higher in dom. order matters events called in order in bound. can cancel events bound after event doing canceling.

i'm not sure if these changes maintain validity of program, demonstrates function's use. otherwise, i'd check right-mousedown in play_sound , exit out instead of banking on event cancel execution.

live demo

$(document).ready(function(){    document.oncontextmenu = function() {return false;};   //for work must bind same object or must bind lower in dom.   $(".sound").mousedown(function(e){      if( event.which == 3 ) {         cancel_playback();         e.stopimmediatepropagation();         return false;      }      return true;    }).mousedown(play_sound); })  function cancel_playback() {     alert("this should displayed on right-mousedown") }  function play_sound() {     alert("display on left-mousedown... not on right-mousedown") } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -