How to disable right-clicking on a hyperlink in html

I need to disable right-clicking on a hyperlink that is in the gap. I need to disable only one link from the whole page. Any suggestions?

+6
source share
6 answers

If you do not want to display the context menu in a hyperlink, you can do this without doing anything with the other part, or even in the place where it exists. I tested in IE, Firefox and it works.

<a href="#" oncontextmenu="return false;"> Link </a> 
+20
source

This should work:

 oncontextmenu="return false;" 

Place it on any item you want to disable. Keep in mind that this leads to a bad user experience, and users can easily turn it off.
Disclaimer: not verified.

+5
source

If you don't want to foul your HTML with inline events, and you care about IE <9 support, you can use this lovely mess:

 function addEvent (el, eventType, listener) { if (el.addEventListener) { // W3C-compliant el.addEventListener(eventType, listener, false); } else {// IE-specific el.attachEvent('on'+eventType, listener); } } addEvent(document.getElementById('myLinkID'), 'contextmenu', function (e) { if (e.preventDefault) { // W3C e.preventDefault(); } else { // IE e.returnValue = false; } }); 
+1
source

I have never seen one made through HTML (this does not mean that it is impossible). However, JavaScript can help you here.

You can do something like:

 var eventbutton = (isNS) ? myevent.which : myevent.button; if((eventbutton==2)||(eventbutton==3)) return false; 
0
source

Try oncontextmenu="return false;"

0
source

IN MVC:

@ Html.ActionLink ("print page", "myprint", "print", null, new {@oncontextmenu = "return false;"})

0
source

Source: https://habr.com/ru/post/888501/


All Articles