1

I am trying to run the following code on IE but not able to get the 'event.which' as '3' / event that alert itself is not coming, when I right click.

 $(document).bind('click', function(event) { 

 alert("event.which = "+event.which);

});

My Base requirement is to bind a click event as above and then if it is a anchor link on which i have clicked then I want to restrict a default options which we usually get on right click like 'Open in new window','BookMark this link' etc.

Thx

erotavlas
  • 4,274
  • 4
  • 45
  • 104
Mr bond
  • 133
  • 2
  • 13
  • you mean you want to customize default context menu of browser according to your needs ??? – Devjosh Feb 01 '12 at 11:29
  • if you want to change the context menu options of browser then must read this post http://stackoverflow.com/questions/654568/overriding-the-right-click-context-menu-in-web-browsers-pros-and-cons – Devjosh Feb 01 '12 at 11:43

3 Answers3

2

If you mean you want to disable right click then:


$(document).ready(function() {
     //disable the right mouse click menu
     $(document)[0].oncontextmenu = function() {return false;}
});

Did you mean something like that.

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
2

Below code should work: (tested in IE 7)

$(document).mousedown(function () {
    if (event.button == 2 && event.srcElement.id == 'your element id') {
        alert('right click not allowed');
        return false;
    }
});
Aliaksei Kliuchnikau
  • 13,589
  • 4
  • 59
  • 72
Dinu
  • 93
  • 2
  • 13
0

if you want to block context menu on anchor element then This will prevent the context menu from appearing on a particular element

$('a').observe("contextmenu", function(e){
    e.stop();
});

So, if you wish to stop all anchor tags from showing a context menu

$('a').each(function(anch){
    $(anch).observe("contextmenu", function(e){
        e.stop();
    });
})

i think you want something different then this but see if this is your need

Devjosh
  • 6,450
  • 4
  • 39
  • 61