I want to disable the contextmenu on my page, because I have an own. But in the textboxes it should be possible to use the system contextmenu.
I'm doing it with Javascript like that:
document.oncontextmenu = function (e) {
return false;
};
I thought about something like:
document.oncontextmenu = function (e) {
if (e.taget.nodeName != "text") {
return false;
}
};
But the nodeName is every time a DIV. In this DIV I have an JQGrid where are the textboxes in.
<div id="divGrdPos" style="padding:3px,0px,3px,0px;">
<table id="JQGridCart" class="grdCart"></table>
</div>
Can someone help me?
You need something like:
document.addEventListener('contextmenu', function (event) {
if (event.target.nodeName !== 'INPUT' && event.target.type !== 'text' && event.target.nodeName !== 'TEXTAREA') {
event.preventDefault();
}
});
It will work for inputs (type="text") and textareas.
Jsfiddle: http://jsfiddle.net/QjmHy/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With