Jquery right click, no contextmenu, live and all browser
Hope somebody can help me.
My first try ... // the rightclick does not workHTML
<div id="test_one" class="my_class">Click here</div>
<br /><br />
<div id="test_two" class="my_class">Click here</div>
JS
$(document).ready(function test()
{
$(".my_class").bind("contextmenu",function(e){ return false; });
$(".my_class").live('click', function(e)
{
if(e.button == 开发者_运维百科0 || e.button == 1)
{
alert('L -> '+this.id+'');
}
else if(e.button == 2){
alert('R -> '+this.id+'');
}
});
});
example: http://jsfiddle.net/EWXse/
Thanks in advance! Peter
According to the documentation of mousedown the right mouse lick is not detectable by default: http://api.jquery.com/mousedown/ .
How to distinguish between left and right mouse click with jQuery suggests that you use event.which instead of event.button, as .which is normalised to 1,2,3 across all browsers.
For what it is worth: right mouse clicks don't seem to work in Google Chrome on Mac OS X here.
精彩评论