I am using onContextMenu() for a few functions, and I'd rather disable the standard context menu to replace it with my own. Right now I have it just alert("does this work?");, so when I right-click on an item, it popus up a box that says "does this work?" then when I click OK, the normal context-menu appears. Is there a way to stop the normal context-menu from appearing?
Okay, so I've figured it out... onContextMenu="javascript:mycoolfunction('some variable');return(false);" Seems to work great, but now I want my own window to pop up. Is there a way to get the x and y coordinates of the mouse during the right click so I can have it display a <div> or something with my features in it right next to the link?
window.event.x (or y), but that's ie only IIRC. <short pause> Yeah, here we go: Breakingpar.com CodeLifter
Now, do I need to always be recording the x and y coordinates of the mouse, or can I just get them when I click somewhere? I'm not quite qure what the function is doing...
Rough and dirty; not checked in any way, shape, or form - nor (if it did work) is it cross browser compliant. Code: #divMenu { background-color: #CCC; display: none; } <div oncontextmenu="showMenu();">right click me</div> <div id="divMenu">menu guff</div> showMenu() { objMenu = document.getElementById('divMenu'); objMenu.top = window.event.y; objMenu.left = window.event.x; objMenu.style.display = 'block'; } Something like that. You also need some code to get rid of the menu if you a) click on it and b) click away from it.
Sorted on MSN. For anyone that's interested, here's a simple - though not necessarily the best (although it is cross browser compliant) - example: .