0

this code work 100% in "google Chrome Browser" but its not working on "Firefix" how i solve this problem?

    $(".one_post").click(function() {

    switch (event.which) {
        case 1:
            window.document.location = $(this).attr("href");
            break;
        case 2:
            $(this).target = "_blank";
            window.open($(this).attr("href"));
            break;
        }
    });

     $(".os_new_ads_lis_city").click(function() {
        window.document.location = $(this).attr("href");
    });

     $(".os_new_ads_list_category").click(function() {
    window.document.location = $(this).attr("href");
    });
  • For Firefox specifically, use [*event.button*](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button), but don't expect it to be reliable (or even implemented) in other browsers. – RobG May 12 '14 at 07:14
  • thanks but i try event.button and its not working –  May 12 '14 at 07:24
  • Trying to detect the right mouse button is problematic, as [*this reference*](http://unixpapa.com/js/mouse.html) points out (and [*this one*](http://perrymitchell.net/article/detecting-which-mouse-button-was-pressed/)). It's a bit old, but if you have a click listener then it's only supposed to respond to left (i.e. primary button) clicks. – RobG May 12 '14 at 07:28

2 Answers2

0

Use mouseup or mousedown instead:

$('.one_post').mouseup(function() {
    switch (event.which) {
        case 1:
            alert('Left');
            break;
        case 2:
            alert('Middle');
            break;
        case 3:
            alert('Right');
            break;
    }
});

Here is a jsFiddle.

Sani Huttunen
  • 23,620
  • 6
  • 72
  • 79
0

Instead of click, use mousedown event, as right click opens context menu, you need to use mouse down instead of mouse click, else prevent event bubbling after right click,

$('#btn').on("mousedown",function(e){
    //  your code
});

Here is a small fiddle demo of mouse down which will help you.

Laxmikant Dange
  • 7,606
  • 6
  • 40
  • 65