I am having trouble figuring out how I can get a custom context menu to
appear at the point of the mouse click. When the user right clicks
inside a text box, I want my custom menu to appear at that point. The
below kind of works unless the page scrolls and is scrolled down the
page a ways. I need the menu to be placed correctly regardless of
scrollbar position.
function setMenu(elm){
document.getElementById('myMenu').style.visibility ='visible';
var x=document.body.scrollLeft + event.screenX;
var y=document.body.scrollTop + event.screenY;
document.getElementById('myMenu').style.left=x;
document.getElementById('myMenu').style.top=y;
}
<input type="text" name="textfield" oncontextmenu="setMenu(this);return
false" />
<div id="myMenu" style="position:absolute;visibility:hidden">
Some links here
</div>
Solutions or pointers for the major browsers appreciated.
John