Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

javascript - in jquery, how to make the right click of the mouse have the same behavior of left click

what i want to realize is : when I right click a link , it also jump to another page like left click. how to do it? thanks very much.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a plugin that will handle a lot of this for you: http://abeautifulsite.net/blog/2008/05/jquery-right-click-plugin/

Or if you wanted to roll your own:

Check out the docs for event.which: http://api.jquery.com/event.which/

You can detect which mouse button was clicked:

$('.clicky').mousedown(function(event) {
switch (event.which) {
    case 1:
    alert('Left mouse button pressed');
    break;
    case 2:
    alert('Middle mouse button pressed');
    break;
    case 3:
    alert('Right mouse button pressed');
       // you would want to prevent default behavior and trigger a click 
       event.preventDefault();
       $(this).trigger('click');
    break;
    default:
    alert('You have a strange mouse');
}
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...