jQuery Right-click Plugin
Written by Cory S.N. LaViska on May 13th, 2008
Easily add right-click functionality and disable browser context menus with this lightweight jQuery plugin.
Contents
Overview
This plugin enables you to use jQuery to attach events triggered by the right mouse button. Three right-click events are supported: rightClick, rightMouseUp, and rightMouseDown. There is also a built-in method to disable browser context menus.
Note that for left-handed users the “right” mouse button is actually on the left. The use of “right” and “left” when referring to mouse buttons has become commonplace, therefore it is used as such in this article to prevent confusion.
Usage
// Capture right click
$("#selector").rightClick( function(e) {
// Do something
});
// Capture right mouse down
$("#selector").rightMouseDown( function(e) {
// Do something
});
// Capture right mouseup
$("#selector").rightMouseUp( function(e) {
// Do something
});
// Disable context menu on an element
$("#selector").noContext();
});
Note: #selector may be any valid jQuery selector.
Demo
Visit the demo page for a full-featured demonstration of this plugin.
Compatibility
This plugin requires jQuery 1.2.6 or higher, and has been tested in the following browsers:
- Firefox 2+
- Internet Explorer 6+
- Chrome
- Safari 3
It is worth mentioning that one cannot currently detect a right click nor disable the context menu in Opera 9 or below. Opera 9.5 introduced an option to allow scripts to detect right clicks, but it is disabled by default and the browser’s context menu still cannot be disabled.
Change Log
Version 1.01
- References to this now work the same way as other jQuery plugins, thus the el parameter has been deprecated (use this or $(this) instead)
- The mouse event is now passed to the callback function
- Changed license to GNU GPL
Download
Current version: Version 1.01 (20 December 2008)
This plugin is provided to you as-is, at absolutely no cost. If you would like to support its development, feel free to contribute any amount you prefer via PayPal. As always, you are welcome to contribute code for bug fixes and feature enhancements as well. Either way, thanks for supporting our efforts!
Limitations
Multiple Events
You cannot combine a rightClick event with a rightMouseUp event. Most browsers do not return a true click event for the right mouse button. Given that, the plugin simulates a true click by detecting the mousedown and mouseup events. If both occur consecutively on the same element, a click event is fired.
Opera Browsers
Since Opera doesn’t support any of the functionality provided by this plugin, it is best to provide alternative ways for your users to achieve the same results wherever right-click events are used.
Licensing
This plugin is dual-licensed under the GNU General Public License and the MIT License and is copyright 2008 A Beautiful Site, LLC.













Comments
— John on Jun 20th, 2008
— Mircea Zetea on Jul 12th, 2008
— Mik Shvets on Aug 6th, 2008
— Tim on Aug 18th, 2008
— Cory S.N. LaViska on Aug 24th, 2008
— Hell Lord on Aug 31st, 2008
— giovanni battista lenoci on Sep 11th, 2008
— Cory S.N. LaViska on Sep 14th, 2008
— Rob on Nov 13th, 2008
— TheBlueSky on Nov 27th, 2008
— Obsidian on Dec 2nd, 2008
— Brian Whitmer on Dec 4th, 2008
— Cory S.N. LaViska on Dec 4th, 2008
— Kikuchyo on Dec 13th, 2008
— Cory S.N. LaViska on Dec 20th, 2008
— Tatu on Dec 23rd, 2008
— Cory S.N. LaViska on Dec 23rd, 2008
— Keivan S. on Jan 9th, 2009
— Cory S.N. LaViska on Jan 9th, 2009
— Keivan S. on Jan 9th, 2009
— Cory S.N. LaViska on Jan 9th, 2009
— Keivan S. on Jan 9th, 2009
— Costas on Jan 15th, 2009
— why on Feb 8th, 2009
— agree on Feb 8th, 2009
— Cory S.N. LaViska on Feb 8th, 2009
— why on Feb 9th, 2009
— Mike on Feb 9th, 2009
— Mike on Feb 9th, 2009
— Michal Hantl on Feb 17th, 2009
— Fatih YASAR on Feb 27th, 2009
— Cory S.N. LaViska on Feb 28th, 2009
— sean on Mar 2nd, 2009
— Kissifrot on Mar 9th, 2009
— Kissifrot on Mar 9th, 2009
— Serg on Mar 13th, 2009
— nick on Mar 15th, 2009
— nick on Mar 15th, 2009
— Serg on Mar 23rd, 2009
— Serg on Mar 24th, 2009
— Tom on Mar 24th, 2009
— Rasit on Apr 2nd, 2009
— Wes on Apr 7th, 2009
— Wes on Apr 7th, 2009
— conficker on May 12th, 2009
— Saugata on May 17th, 2009
— Tim Down on May 22nd, 2009
— Tim Down on May 22nd, 2009
— Sedat Kumcu on Jun 21st, 2009
— Mario Soto on Jun 26th, 2009
— palamedes on Jun 26th, 2009