admin管理员组文章数量:1022944
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?
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?
Share Improve this question edited May 18, 2021 at 6:17 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Oct 19, 2012 at 6:54 SenniSenni 831 silver badge6 bronze badges3 Answers
Reset to default 6You 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/QjmHy/
Why are you checking against text
textbox nodeName
is INPUT
document.oncontextmenu = function (e) {
console.log(e);
if (e.target.nodeName != "INPUT") {
return false;
}
};
http://jsfiddle/qr3fu/
I found the mistake.
In my code I have a mousedown()
event on my grid and this event fires before the oncontextmenu()
event. and my mousedown()
is greating my own contextmenu with a div
after checking the right click.
So I checked in my mousedown()
event if the nodeName
is "input"
and handle the result.
the oncontextmenu()
will be the same.
thx for your tips.
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?
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?
Share Improve this question edited May 18, 2021 at 6:17 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Oct 19, 2012 at 6:54 SenniSenni 831 silver badge6 bronze badges3 Answers
Reset to default 6You 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/QjmHy/
Why are you checking against text
textbox nodeName
is INPUT
document.oncontextmenu = function (e) {
console.log(e);
if (e.target.nodeName != "INPUT") {
return false;
}
};
http://jsfiddle/qr3fu/
I found the mistake.
In my code I have a mousedown()
event on my grid and this event fires before the oncontextmenu()
event. and my mousedown()
is greating my own contextmenu with a div
after checking the right click.
So I checked in my mousedown()
event if the nodeName
is "input"
and handle the result.
the oncontextmenu()
will be the same.
thx for your tips.
本文标签: javascriptDisable contextmenu but NOT in textboxesStack Overflow
版权声明:本文标题:javascript - Disable contextmenu but NOT in textboxes - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745559713a2156087.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论