admin管理员组文章数量:1313121
using vanilla js. Any way to grab the "right-click" (option-click) from OSX?
function clickey(e)
{
if(event.button==2 || /*how you'd do it in Java=)*/ e.getButton() == MouseButton.BUTTON3 )
...
}
but in js, how do eeet?
using vanilla js. Any way to grab the "right-click" (option-click) from OSX?
function clickey(e)
{
if(event.button==2 || /*how you'd do it in Java=)*/ e.getButton() == MouseButton.BUTTON3 )
...
}
but in js, how do eeet?
Share Improve this question edited Feb 6, 2013 at 15:30 Andrew Barber 40.2k20 gold badges97 silver badges124 bronze badges asked Feb 6, 2013 at 9:41 FlavorScapeFlavorScape 14.3k12 gold badges79 silver badges123 bronze badges 1- would i just have to pickup the keycode? – FlavorScape Commented Feb 6, 2013 at 10:02
2 Answers
Reset to default 5You need to listen to the contextmenu
event. This is triggered when the context menu should be shown. So either if the right mouse butten or or ctrl + mouse.
If it is not supported then you can try to check the mousedown
event where button
is 2
and ctrlKey
is true
if it is triggered by using ctrl + mouse
document.addEventListener("contextmenu",function(event){
});
OR (depending on what the browser supports)
document.addEventListener("mousedown",function(event){
if( event.ctrlKey || event.button == 2 ) {
}
});
edit: removed the which
info
I'm not experienced with OSX, but the Mouse Events have the option to check the modifier keys. So something along these lines should work:
DOMElement.addEventListener("click",function(event){
// either check directly the button
if (event.button == 2){}
// or
if (event.ctrlKey || event.altKey || event.metaKey){
// do stuff
}
});
本文标签: eventsany way to detect ctrlclick in javascript for osx browsers no jQueryStack Overflow
版权声明:本文标题:events - any way to detect ctrl + click in javascript for osx browsers? no jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741916133a2404741.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论