admin管理员组文章数量:1389803
Ok so as far as I understand it so far we have 2 approaches
Firstly some javascript which I can employ within a given script. But this switches right click off for everything.
window.oncontextmenu = function() {
return false;
};
or in the html can code
<body oncontextmenu="return false;">
but I cannot thus far find anywhere that will give me javascript or jquery solution where I can apply this to a given selector. Is this simply not possible or am I mis-understanding something.
I am finding that on a single right click my submenu appears immediately followed by the browser's default menu. The only way I have found to suppress this is setting oncontextmenu to false. Is there a more refined solution?
Further Note to accepted answer
Also applied successfully on a dynamic menu using delegate:
$(document).on("contextmenu", "#existing_Flavours .field_Input_Left.flavour", function(){
return false; // suppress browsers default right click menu
});
Ok so as far as I understand it so far we have 2 approaches
Firstly some javascript which I can employ within a given script. But this switches right click off for everything.
window.oncontextmenu = function() {
return false;
};
or in the html can code
<body oncontextmenu="return false;">
but I cannot thus far find anywhere that will give me javascript or jquery solution where I can apply this to a given selector. Is this simply not possible or am I mis-understanding something.
I am finding that on a single right click my submenu appears immediately followed by the browser's default menu. The only way I have found to suppress this is setting oncontextmenu to false. Is there a more refined solution?
Further Note to accepted answer
Also applied successfully on a dynamic menu using delegate:
$(document).on("contextmenu", "#existing_Flavours .field_Input_Left.flavour", function(){
return false; // suppress browsers default right click menu
});
Share
Improve this question
edited Dec 3, 2012 at 20:45
codepuppy
asked Dec 3, 2012 at 20:08
codepuppycodepuppy
1,1402 gold badges15 silver badges25 bronze badges
6
- 1 Don't do it. It's annoying and your users will A) never visit your site again or B) bypass it via script blockers and/or manually. – jbabey Commented Dec 3, 2012 at 20:11
- This is an exact duplicate. stackoverflow./questions/706655/… – Andrew Hubbs Commented Dec 3, 2012 at 20:12
- Well I can't say that I fully understand why that should be. But I am sure you are right. But surely there must be a way to stop the default menu from appearing where right click is being used. @jbabey – codepuppy Commented Dec 3, 2012 at 20:14
-
@Andrew - the thing about your referenced question, is that the accepted answer is wrong.
contextmenu
is now supported in jQuery. – ahren Commented Dec 3, 2012 at 20:15 - @ahren They are both right and both answers are in that question, which is the exact same question as this one. – Andrew Hubbs Commented Dec 3, 2012 at 21:22
1 Answer
Reset to default 7$('#mySelector').on('contextmenu', function(){
return false;
});
Just bind it like you would any other event...
However, if you're wanting to do this to "protect" content, it's very little security. It's easy to bypass.
Demo: http://jsfiddle/V3sWc/
本文标签: javascriptSuppressing a Browsers Default Right Click MenurefinementStack Overflow
版权声明:本文标题:javascript - Suppressing a Browsers Default Right Click Menu - refinement? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744605902a2615352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论