0

Is there a way to detect a right mouse click then refresh.

To detect a right mouse click I use:

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

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

}
}

In myFunction I wanna detect "refresh" item is clicked.

I use IE browser.enter image description here

senior
  • 2,196
  • 6
  • 36
  • 54

3 Answers3

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

  $(document).mousedown(function(e){ 
    if( e.button == 2 ) { 
      window.location.reload();
      return false; 
    } 
    return true; 
  }); 
});
Mathias Dewelde
  • 665
  • 9
  • 19
  • I like: document.oncontextmenu = function() {return false;}; +1 It solves a part of my problem :) Thanks – senior May 21 '14 at 15:33
1

event.which == 3 shows that it is a right click

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

For more information SEE and JSFIDDLE DEMO

Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79
  • After I detect a right mouse click, I wanna click the refresh item. How can I detect that the refresh item is clicked? – senior May 21 '14 at 13:50
  • You should also prevent the default behaviour of right clicking. document.oncontextmenu = function() {return false;}; – Mathias Dewelde May 21 '14 at 13:50
  • I think you want to look for the `window.onunload` since the page will be refreshing. Your requirements are not crystal clear, if you would like to clarify some more .... – PeterKA May 21 '14 at 13:55
  • @lolita see http://vinodvillain1986.blogspot.in/2013/03/disable-refresh-button-on-browser-using.html – Rakesh Shetty May 21 '14 at 13:56
  • @RakeshShetty you should put it into some fiddle and shows that it works. I doubt that it just disables the **F5** key, while user can always use mouse to refresh the page (even he can use the Refresh button of the browser). – King King May 21 '14 at 14:00
0

You can use this code:

$("#refresh").mousedown(function(e) { if (e.which === 3) { 
     alert('element with id "refresh" clicked!');
 } });
Meowsome
  • 99
  • 1
  • 10