Capturing right-click events, and detecting click location

by Michael Underwood

HTML

<body>
Lorem ipsum...
</body>

JavaScript

if (document.addEventListener) {
        document.addEventListener('contextmenu', function(e) {
            alert("You've tried to open context menu at (" + e.x + "," + e.y + ")"); //here you draw your own menu
            e.preventDefault();
        }, false);
    } else {
        document.attachEvent('oncontextmenu', function() {
            alert("You've tried to open context menu");
            window.event.returnValue = false;
        });
    }