afru
02-09-2005, 06:40 PM
Problem : How to capture right click from inside <a> tag or <img > tag through onmousedown or onmouseup events and disable context menu?
Below is the code I have tried to implement.
<SCRIPT LANGUAGE="JavaScript">
<!--
function myhandler(e)
{
//// do something with event obj......
return false;
}
//-->
</SCRIPT>
<a href="http://www.yahoo.com" onmousedown="return myhandler(event);"
onmouseup="return myhandler(event);"
onclick="return myhandler(event);">
Right click should be disabled on this item.</a>
I want to disable right click only on particular links or images. So I wrote the above code. What is wrong with above code. Why does the browser not responding to return false; I just want to capture mouse events and use them as per my purpose and then disable them all by returning false.
I think onclick is working fine and so the browser is not going to yahoo.com But when you right click, none of the code is working. It is displaying right context menu of the browser.
I know how to add event listener to a particular ID. But what I dont want to write code for particualr IDs. I want to capture right click event from inside of <a href> tag or <img> tag where ever I need it and then disable right context menu.
Hope somebody will work out what is wrong with above code.
A working cross browser example will be fabulous.
Thanking you.
Afru.
Below is the code I have tried to implement.
<SCRIPT LANGUAGE="JavaScript">
<!--
function myhandler(e)
{
//// do something with event obj......
return false;
}
//-->
</SCRIPT>
<a href="http://www.yahoo.com" onmousedown="return myhandler(event);"
onmouseup="return myhandler(event);"
onclick="return myhandler(event);">
Right click should be disabled on this item.</a>
I want to disable right click only on particular links or images. So I wrote the above code. What is wrong with above code. Why does the browser not responding to return false; I just want to capture mouse events and use them as per my purpose and then disable them all by returning false.
I think onclick is working fine and so the browser is not going to yahoo.com But when you right click, none of the code is working. It is displaying right context menu of the browser.
I know how to add event listener to a particular ID. But what I dont want to write code for particualr IDs. I want to capture right click event from inside of <a href> tag or <img> tag where ever I need it and then disable right context menu.
Hope somebody will work out what is wrong with above code.
A working cross browser example will be fabulous.
Thanking you.
Afru.