Hello All,

I am trying to disable right click only for specific links on the page> I want to create my own pop up menu for these eventually. At present I have the following

<a href='#' onContextMenu="typesclick()">Types</a>

the function is

function typesclick()
{

alert("testing");
return false;


}

The alert appears but the browser context menu also appears. I am using ie7? Any ideas why this is not working?

Scott Bailey

A quick example on how to disable right click for specific link!
Hope you had a great time! Enjoy...

<html>
<head>
<title>noRclick</title>
<script type="text/javascript">
<!--
document.onclick = function( e )
{ e = e ? e : window.event;
  t = e.target ? e.target : e.srcElement;
if (( t.name ) && ( t.name == 'link1' ) && ( e.which == 2 ) || ( e.which == 3 )) { alert('\nSorry right click has been disabled for this link!'); return false; } 
else 
{ 
return true; 
 } 
}
//-->
</script>
</head>
<body>
<a name="link1" href="#"> Link One</a><br />
<a name="link2" href="#">Link Two</a>
</body>
</html>

If you have any question regarding this code! Just let me know about it... Enjoy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.