Disabling the Right-Click Menu For an Image

JavaScript FAQ | Keyboard & Mouse Events FAQ  

Question: Can I disable the right-click context menu for a particular image, while still enabling the menu for all other parts of my page?

Answer: Yes. In most modern browsers you can disable the right-click menu for a particular image. To do so, you can use the event handler

oncontextmenu="return false;"
within the
IMG 
tag that defines your image:
<IMG border=0 src="..." oncontextmenu="return false;">
For example, the context menu has been disabled for this image:

Note: In older browsers (e.g. Internet Explorer 4.x or earlier) this trick won't work. Also, the context menu will show up if the user has disabled JavaScript.

Copyright © 1996-2018, JavascriptFAQ.net.