In fact, do not Bootstrap also do, purely for good-looking ...
The first thing to do is to screen out the browser's default right-click menu where you need to pop the right button:
<div id= "Rightmenuparentdiv" oncontextmenu= "ShowMenu (); return false;" >
<div id= "Rightmenudiv" >
123
</div>
</div>
Then write ShowMenu this function:
function ShowMenu () {
document.getElementById ("tree"). onmousedown = function (e) {
if (E.which = = 3) {
if (!e ) {
e = window.event;
} else {
e.srcelement = e.target;
}
if (e.srcelement.innerhtml!= "") {
document.getElementById ("Rightmenu"). Style.left = E.clientx + "px";
document.getElementById ("Rightmenu"). Style.top = E.clienty + "px";
document.getElementById ("Rightmenu"). Style.display = "Block";}}}
Write the right button in the Body menu:
<div class= "Panel Panel-default" style= "position:absolute;display:none;z-index:999;padding:0;margin:0; line-height:0 "id=" Rightmenu "> <div class=" panel-body "style=" margin:0;padding:0
; >
<ul class= "nav nav-pills nav-stacked" >
<li><a href= "#" > I heard I was the first menu item </a></li >
<li><a href= "#" > I am the second menu item </a></li>
<li><a href= "#" > I'm the last one. </a ></li>
</ul>
</div>
</div>
Here are some CSS styles in the bootstrap.
In order for the menu to disappear in time, you need to add a function to the javascript:
function Hiddenrightmenu () {
document.getElementById ("Rightmenu"). Style.display = "None";
}
and add it to the body tag:
<body onclick= "Hiddenrightmenu ();" >
</body>
This allows the right-click menu to pop up and hide it in time.