Reputation: 3855
I'm dealing with a page which contains some JS that I'm unable to modify being loaded onto the page which fires off a function when an element is right clicked. So, I know how to capture the right click on elements on the page, but is there a way for me to specifically unbind all right clicks and ONLY right clicks on elements?
Obviously it would have been awesome if something like $(selector).unbind('rightclick)
worked but it doesn't of course.
Any help would be greatly appreciated.
EDIT
Some clarification... I'm not looking to prevent the default right click browser menu from appearing when the element is right clicked. I simply want to remove all things bound to fire off when the element is right clicked. When I did this targeting all clicks, it worked fine and the default menu appeared. The only problem then was that I also unbound all left click events, which is what I'm trying to avoid.
Basically, this event that I'm trying to unbind prevents the context menu from appearing at all. So I'm trying to unbind that even in order to show it.
Upvotes: 2
Views: 1329
Reputation: 18589
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>jQuery disable right click easily</title>
<script language="javascript" type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
$(function() {
$(this).bind("contextmenu", function(e) {
e.preventDefault();
});
});
</script>
</head>
<body>
Sed lacus. Donec lectus. Nullam pretium nibh ut turpis.
Nam bibendum. In nulla tortor, elementum vel, tempor at,
varius non, purus. Mauris vitae nisl nec consectetuer.
Donec ipsum. Proin imperdiet est. Phasellus dapibus semper
urna. Pellentesque ornare, orci in consectetuer hendrerit,
urna elit eleifend nunc, ut consectetuer nisl felis ac diam.
Etiam non felis. Donec ut ante. In id eros.
</body>
</html>
Upvotes: 1