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: click, mouseup, and mousedown. 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.
Compatibility
This plugin has been tested in the following browsers:
- Firefox 2+
- Internet Explorer 6+
- Safari 3
It is worth mentioning that one cannot currently detect a right click nor disable the context menu in Opera 9 or below.
Usage
// Capture right click
$("#selector").rightClick( function(el) {
// Do something
});
// Capture right mouse down
$("#selector").rightMouseDown( function(el) {
// Do something
});
// Capture right mouseup
$("#selector").rightMouseUp( function(el) {
// 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.
Download
Current version: Version 1.0 (13 May 2008)
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 & Terms of Use
This plugin is licensed under a Creative Commons License and is copyrighted ©2008 by Cory S.N. LaViska.


Comments
#1 John on Jun 20th, 2008
#2 Mircea Zetea on Jul 12th, 2008
#3 Mik Shvets on Aug 6th, 2008
#4 Tim on Aug 18th, 2008
#5 Cory S.N. LaViska on Aug 24th, 2008