Answering your question - use contextmenu event, like below: <html><head><scripttype="text/javascript">if (document.addEventListener) { // IE >= 9; other browsers document.addEventListener('contextmenu', function(e) { alert("You've tried to open context menu"); //here you draw your own menu e.preventDefault(); }, false); } else{ // IE < 9 document.attachEvent('oncontextmenu', function() { alert("You've tried to open context menu"); window.event.returnValue = false; }); } </script> </head> <body> Lorem ipsum... </body> </html> But you should ask yourself, do you really want to overwrite default right-click behavior - it depends on application that you're developing.
ES6 버전으로 바꾸어 보겠다.
//ES6 Class Version, add On, Off
// private properties: let priCSMsgLis = { _bShowSysContextMenu: Symbol(), };
export class CContextMenu { constructor() {
//기본상태는 팝메뉴를 보여주는 것으로 한다. this[priCSMsgLis._bShowSysContextMenu] = true;
this.init(); }
init() {
//자신이 쓰는 domElement 객체를 넣어주면 된다.
//여기서는 스크립트 전역에 쓰는 document
을 쓰겠다.
let dom = document;
this.initContextMenuLis(dom); }
initContextMenuLis(dom) { let me = this;
if (dom.addEventListener) { // IE >= 9; other browsers dom.addEventListener('contextmenu', function(e) { if(!me.isShowSysContextMenu) { //alert("You've tried to open context menu"); //here you draw your own menu e.preventDefault(); } }, false); } else { // IE < 9 dom.attachEvent('oncontextmenu', function() { if(!me.isShowSysContextMenu) { // alert("You've tried to open context menu"); window.event.returnValue = false; } else { window.event.returnValue = true; } }); } }