javascript - right click event on IE - Stack Overflow

I am trying to run the following code on IE but not able to get the 'event.which' as '3&

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 ing, 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

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 ing, 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

Share Improve this question edited Jun 20, 2016 at 18:19 erotavlas 4,5135 gold badges56 silver badges121 bronze badges asked Feb 1, 2012 at 11:16 Mr bondMr bond 1332 silver badges16 bronze badges 2
  • you mean you want to customize default context menu of browser according to your needs ??? – Devjosh Commented Feb 1, 2012 at 11:29
  • if you want to change the context menu options of browser then must read this post stackoverflow./questions/654568/… – Devjosh Commented Feb 1, 2012 at 11:43
Add a ment  | 

3 Answers 3

Reset to default 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.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745382620a4625298.html

相关推荐

  • javascript - right click event on IE - Stack Overflow

    I am trying to run the following code on IE but not able to get the 'event.which' as '3&

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信