any way to detect ctrl + click in javascript for osx browsers? no jQuery

后端 未结 2 1261
猫巷女王i
猫巷女王i 2020-12-20 04:31

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         


        
2条回答
  •  自闭症患者
    2020-12-20 05:38

    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
       }  
    });
    

提交回复
热议问题