检测鼠标右键+刷新

时间:2014-05-21 13:40:29

标签: jquery html

有没有办法检测鼠标右键然后刷新。

要检测鼠标右键,我使用:

jQuery(document).on("mousedown",myFunction); 

function myFunction(e){
...
if( e.button == 2 ) { 

}
}

在myFunction中,我想要点击“刷新”项目。

我使用IE浏览器。enter image description here

3 个答案:

答案 0 :(得分:2)

$(document).ready(function(){ 
  document.oncontextmenu = function() {return false;};

  $(document).mousedown(function(e){ 
    if( e.button == 2 ) { 
      window.location.reload();
      return false; 
    } 
    return true; 
  }); 
});

答案 1 :(得分:1)

event.which == 3表示这是一次右键点击

$('#element').mousedown(function(event) {
    switch (event.which) {        
        case 3:
            location.reload();
            break;
    }
});

有关详情SEEJSFIDDLE DEMO

答案 2 :(得分:0)

您可以使用此代码:

$("#refresh").mousedown(function(e) { if (e.which === 3) { 
     alert('element with id "refresh" clicked!');
 } });
相关问题