html:
<div id="menu">
<li>重新加载</li>
<li>返回</li>
<li>另存为</li>
<li>打印</li>
</div>
js:
// 自定义右键菜单;
// 获取menu元素;
var menu = document.getElementById("menu");
// 首先取消右键菜单的默认事件
window.oncontextmenu = function(e){
var e = e || window.event;
menu.style.display = "block";
menu.style.left = e.clientX + "px";
menu.style.top = e.clientY + "px";
return false;
}
menu.onclick = function(e){
e.stopPropagation();
}
window.onclick = function(){
menu.style.display = "none";
}