I've found that this code appears to block the right-click pop-up menu:

document.oncontextmenu = function () { return false; };

However, I need for it to be treated like a left-click. This is used on a form with radio buttons where students are making choices. Thanks for your help.

I think Jeff's solution takes care of the original issue. In conjunction with it, I need an alert-type ok/cancel box to fire when the user clicks a submit button, but I need for it to (1) block the right-click, and (2) ignore keypresses (particularly the Enter key). Is this doable? Thanks.

有帮助吗?

解决方案

Use event.target and click():

document.oncontextmenu = function (event) {
    event.target.click();
    return false;
}

JSFiddle Demo: http://jsfiddle.net/EF47L/

其他提示

If you were using jquery you could trigger a click event for the DOM element.

See http://api.jquery.com/click/

Or Javascript

var l = document.getElementById('my-el');
l.onclick();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top