I've written a plugin for jQuery to handle right click events.
The plugin provides two features:
$( ... ).disableContextMenu( condition_event );
This function disables the browsers build-in contextmenu (right-click menu on PC's).
condition_event - is an optional parameter, it's meant to be a function-reference to determine if the contextmenu should be shown, the function must return true if the menu is allowed to be shown and must return false if the menu is not to be shown. If condition_event is not provided or returns a non-boolean value, the contextmenu will be disabled.
Please note: This is not a way to stop your users from downloading images or viewing source code, this is only meant to be used as when it's better for the usability.
$( ... ).rightClick( callback, contextmenu_condition_event );
This function will let you create your own event for right click, it can be used to create your own contextmenu.
It takes two paramters.
callback - Is the event which will be called on right click. (required)
contextmenu_condition_event - will be parsed to disableContextMenu.
I also provide functions to remove these event from an element:
$( ... ).enableContextMenu( );
Will undo the function $( ... ).disableContextMenu( );
$( ... ).removeRightClick( );
Will remove the rightClick event from the element.
Copyright (c) 2009 Morten Sjoegren <email@example.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You can download the plugin including a simple example here.