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來代替默認的上下文菜單?
謝謝。