JavaScript Custom Right-click menu code:
Right-click menu this is more familiar with the use of computer words almost every day to operate on the Times right-click menu, below to share a custom right-click menu code example, I hope to be able to help people who need relevant content, code examples are as follows:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.51texiao.cn/" /><title>Ant Tribe</title><styletype= "Text/css">#d1{width:100px;Height:200px;Background-color:Green;Display:None;}#dl a{Display:Block;}</style><Scripttype= "Text/javascript">window.onload=function() {Rightmenu ('P1','D1');} functionRightmenu (elementid,menuid) {varMenu=document.getElementById (MenuID); //Get Menu Object varelement=document.getElementById (elementid);//get click on the element that has a custom right buttonElement.onmousedown=function(aevent) {//sets the right-click handler function for the element by pressing the mouse button if(window.event) aevent=window.event; //Resolving Compatibility if(Aevent.button==2) { //when the value of the event property button is 2 o'clock, the table user presses the right keyDocument.oncontextmenu=function(aevent) {if(window.event) {aevent=window.event; Aevent.returnvalue=false; //Default Right-click event handler for IE interrupt}Else{aevent.preventdefault (); //Default Right-click event handler for standard DOM interrupts}} menu.style.cssText='Display:block;top:'+Aevent.clienty+'px;'+'Left :'+Aevent.clientx+'px;' //position the menu relative to the mouse}} menu.onmouseout=function() { //Hide menu When setting mouse out menuSetTimeout (function() {Menu.style.display="None";}, -); }} </Script></Head><Body><PID= "P1">Right-click on the menu that appears to me</P><DivID= "D1"> <a>Shear</a> <a>Copy</a> <a>Paste</a></Div></Body></HTML>
The above code to achieve the basic needs of the effect, of course, is not perfect, can be self-improvement, just provide a way of thinking.
The original address is: http://www.51texiao.cn/javascriptjiaocheng/2015/0507/885.html
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8097
JavaScript Custom Right-click menu code