Question

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.

Was it helpful?

Solution

Use event.target and click():

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

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

OTHER TIPS

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top