Not that I’m trying to prevent ‘View Source’ or anything silly like that, but I’m making some custom context menus for certain elements.
EDIT: response to answers: I’ve tried this:
<a id='moo' href=''> </a> <script type='text/javascript'> var moo = document.getElementById('moo'); function handler(event) { event = event || window.event; if (event.stopPropagation) event.stopPropagation(); event.cancelBubble = true; return false; } moo.innerHTML = 'right-click here'; moo.onclick = handler; moo.onmousedown = handler; moo.onmouseup = handler; </script>
Capture the
onContextMenuevent, and return false in the event handler.You can also capture the click event and check which mouse button fired the event with
event.button, in some browsers anyway.