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, andrightMouseDown. 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.
Contents
Usage
$(document).ready( function() {
// 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:#selectormay 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 tothisnow work the same way as other jQuery plugins, thus theelparameter has been deprecated (usethisor$(this)instead)
- The mouse event is now passed to the callback function
- Changed license to GNU GPL
Download
Current version: jQuery Right Click – 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 arightClickevent with arightMouseUpevent. Most browsers do not return a true click event for the right mouse button. Given that, the plugin simulates a true click by detecting themousedownandmouseupevents. 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.