JavaScript Custom Right-click menu code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.