oncontextmenu

In this example below you will see how to do a oncontextmenu with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 2ndow, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 2ndow ©
  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>oncontextmenu</title>
  
  
  
      <style>
      /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */
      ul{
    width: 100px;
    padding: 5px;
    border: 1px solid #ddd;
    background: #ddd;
    box-shadow: 0px 0px 10px #ccc;
    text-align: center;
    visibility: hidden;
    position: absolute;
}
li{
    list-style: none;
    padding: 5px;
    border-bottom: 1px solid #ccc;
}
ul > li{
    margin: 10px auto;
    padding: 5px;
}

a{
    color: #3c3c65;
    font-size: 1em;
    text-decoration: none;
}
ol{
    width: 100px;
    margin: 0px 110px;
    background: #ddd;
    box-shadow: 0px 0px 10px #ccc;
    position: absolute;
    left: 0;
    opacity: 0;
}
li:hover>ol{opacity: 1;}
    </style>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>

</head>

<body>

  <h1>click muose right</h1>
<ul>
        <li><a href="#">andrew</a></li>
        <li><a href="#">andrew ></a>
        <ol>
            <li><a href="#">andrew</a></li>
            <li><a href="#">andrew</a></li>
        </ol></li>
        <li><a href="#">andrew</a></li>
        <li><a href="#">andrew</a></li>
        <li><a href="#">andrew ></a>
        <ol>
            <li><a href="#">andrew</a></li>
            <li><a href="#">andrew</a></li>
            <li><a href="#">andrew ></a>
            <ol>
                <li><a href="#">andrew</a></li>
                <li><a href="#">andrew</a></li>
            </ol>
            </li>
        </ol></li>

    </ul>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/2ndow/oncontextmenu-KQymdb */
ul{
    width: 100px;
    padding: 5px;
    border: 1px solid #ddd;
    background: #ddd;
    box-shadow: 0px 0px 10px #ccc;
    text-align: center;
    visibility: hidden;
    position: absolute;
}
li{
    list-style: none;
    padding: 5px;
    border-bottom: 1px solid #ccc;
}
ul > li{
    margin: 10px auto;
    padding: 5px;
}

a{
    color: #3c3c65;
    font-size: 1em;
    text-decoration: none;
}
ol{
    width: 100px;
    margin: 0px 110px;
    background: #ddd;
    box-shadow: 0px 0px 10px #ccc;
    position: absolute;
    left: 0;
    opacity: 0;
}
li:hover>ol{opacity: 1;}

/*Downloaded from https://www.codeseek.co/2ndow/oncontextmenu-KQymdb */
var ul = document.querySelector("ul");
document.oncontextmenu = function (e) {
    "use strict";
    ul.style.visibility = "visible";
    ul.style.left = e.clientX + "px";
    ul.style.top = e.clientY + "px";
    return false;
};
document.onclick = function () {
    "use strict";
    ul.style.visibility = "hidden";
};

Comments