+ 1
Context menu
How can I create context menu items in chrome using html and JavaScript? I know you can use Firefoxâs contextmenu: <div oncontextmenu=âfunction()â contextmenu=âId name for future referenceâ></div> But this does not work for any other browser. Anybody with the same problem or solutions. Only JavaScript, html. Thanks
4 Answers
+ 2
You can't edit the original context menu. You need to create your own.
<div class="parent" oncontextmenu="menu(event)">
<div class="contextmenu" id="contextmenu">
<ul>
<li>Item</li>
</ul>
</div>
</div>
.parent {
position: relative;
}
.parent .contextmenu {
position: absolute;
display: none;
}
function menu(event) {
var menu = document.getElementById("contextmenu");
menu.style.left = event.offsetX + "px";
menu.style.top = event.offsetY + "px";
menu.style.display = "block";
event.preventDefault();
}
+ 1
I was just using the name âfunction()â and âid name for future referenceâ as examples. I am more interested in how to change/add items to the context menu
+ 1
Ok that makes a lot of sense. Thank you Toni Isotalo and Nomeh Uchenna Gabriel. Thatâs really helpful. Thanks!
0
context menu works well on an item only if it's "user-select" css property was set to "none"