Click to See Complete Forum and Search --> : Javascript Mouse Events - Right Mouse Click


cmelnick
04-25-2003, 08:00 PM
Hopefully a quick question:

I have items (links) on my page that if you left-click on them they go to the corresponding page. However, if you right-click them, a customized menu comes up. My problem is that I don't want the default right-click browser menu to pop up. I have tried using the event.cancelBubble parameters, but have thus far been unsuccessful. I am most interested in IE code, but would ultimately like IE & Netscape. I have seen other examples of this working, but all involved an alert dialog, which I don't want.

My basic code is as follows:


<a href="url goes here" onMouseDown="return openMenu(event);">
<span id="menu" style="width: 25px; height: 40px; visibility: hidden; top: 0px; left: 0px">Menu goes here</span>
<script language="javascript">
function openMenu(evt) {
if (evt.button == 2) {
var elem = document.getElementById("menu").style;
elem.top = evt.y + "px";
elem.left = evt.x + "px";
elem.visibility = "visible";

// Not sure how to keep event from propagating up to
// the browser menu.
}
}
</script>

havik
04-25-2003, 08:07 PM
Try this:
http://www.dynamicdrive.com/dynamicindex1/contextmenu.htm
or this:
http://www.dynamicdrive.com/dynamicindex1/contextmenu2.htm

Havik

cmelnick
04-25-2003, 10:28 PM
Thanks for the info... I will definently use that too...however, that seems to be for context menu of a whole page, whereas I need it just over a link. When you right-click on the page, I don't care if you get the default context menu. If you right-click on a link, I want a special menu.

Thanks in advance...

Chris

cmelnick
04-26-2003, 12:14 PM
That's the solution...guess I missed the event.returnValue part...

Thanks!