简体   繁体   中英

right click event on IE

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

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.

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;
    }
});

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM