0
已经仔细阅读:How to add a custom right-click menu to a webpage?创建上下文菜单
所以我有2个HTML文件和1个JS脚本。我根本不使用JQuery。
popup.html
<!DOCTYPE html>
<head>
<title id="title">Datajuggler</title>
</head>
<body>
<script src="popup.js"></script>
</body>
</html>
popup.js
var xhr = new XMLHttpRequest();
xhr.open("GET", "contextmenu.html");
xhr.send();
document.addEventListener("contextmenu", function(e) {
// how do I draw the context menu here?
e.preventDefault();
});
contextmenu.html
<div id="menu">
<ul>
<li><a href="http://www.google.com">Google</a></li>
<li><a href="http://www.youtube.com">Youtube</a></li>
</ul>
</div>
所以这是非常简单的。我从contextmenu.html
拉上下文菜单HTML,并且我希望这个div显示每当我用鼠标右键单击(contextmenu事件监听器)。但是,如何显示这个div来代替默认的上下文菜单?
谢谢。