<html>
<head>
<style>
div {
background: yellow;
border: 1px solid black;
padding: 10px;
}
</style>
</head>
<body>
<p>该实例使用了 addEventListener() 方法向 div 元素添加 "contextmenu" 事件。</p>
<div id="myDIV" contextmenu="mymenu">
<p>R在框中点击鼠标右键查看上下文菜单!
</p><menu type="context" id="mymenu">
<menuitem label="Refresh" onclick="window.location.reload();" icon="ico_reload.png"></menuitem>
<menu label="Share on...">
<menuitem label="Twitter" icon="ico_twitter.png" onclick="window.open('//twitter.com/intent/tweet?text=' + window.location.href);"></menuitem>
<menuitem label="Facebook" icon="ico_facebook.png" onclick="window.open('//facebook.com/sharer/sharer.php?u=' + window.location.href);"></menuitem>
</menu>
<menuitem label="Email This Page" onclick="window.location='mailto:?body='+window.location.href;"></menuitem>
</menu>
</div>
<p id="demo"></p>
<script>
document.getElementById("myDIV").addEventListener("contextmenu", myFunction);
function myFunction() {
var x = document.getElementById("demo");
x.innerHTML = "你在 div 中点击了鼠标右键!";
x.style.fontSize = "30px";
}
</script>
<p><strong>注意:</strong> 只有 Firefox 中支持 contextmenu <strong>属性</strong> !</p>
</body>
</html>