Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable right-click on a hyperlink in html

Tags:

html

I need to disable right-click on a hyperlink which is in a span. I need to disable only one link from the whole page. Any suggestions?

like image 863
Tanu Avatar asked May 19 '11 05:05

Tanu


People also ask

How do I restrict right click on a web page in HTML?

Disable right click menu in html page using jquery. JavaScript Code: $(document). bind("contextmenu",function(e){ return false; });

How do I turn off click on links?

Disable a link # It is still possible to disable a link by following 3 steps: remove the href attribute so that it can no longer receive the focus. add a role="link" so that it is always considered a link by screen readers. add an attribute aria-disabled="true" so that it is indicated as being disabled.


2 Answers

If you dont want to show the context menu on hyperlink, you can do so without doing anything to other part or even span where it exists. I tested in IE, Firefox and it works.

<a href="#" oncontextmenu="return false;"> Link </a>
like image 120
AjayR Avatar answered Oct 20 '22 21:10

AjayR


This should work:

oncontextmenu=”return false;”     

Place it on any element you want to disable right click for.
Be aware that this causes bad user experience and users can disable it very easily.
Disclaimer: not tested.

like image 41
Kamyar Avatar answered Oct 20 '22 23:10

Kamyar