Use event.target
and click()
:
document.oncontextmenu = function (event) {
event.target.click();
return false;
}
JSFiddle Demo: http://jsfiddle.net/EF47L/
Pergunta
I've found that this code appears to block the right-click pop-up menu:
document.oncontextmenu = function () { return false; };
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.
Solução
Use event.target
and click()
:
document.oncontextmenu = function (event) {
event.target.click();
return false;
}
JSFiddle Demo: http://jsfiddle.net/EF47L/
Outras dicas
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();