4

I want to open a popup window when someone clicks an area with the right mouse button. I am using this at the moment:

$("#popup").bind('mousedown', function(e) {
    var w;
    if(e.which==3) {
        w=window.open('link','_blank','options');
    } else {
        return false;
    }
    if(w!=null){
        w.focus();
    }
    event.preventDefault();
});

When using it with firefox (haven't tested with other browsers though) the popup is being blocked. I have noticed that with the "click" event it doesn't work at all.

Is there any way to open a popup window when right clicking on something without it being blocked by a browser?

Anderson Pimentel
  • 5,086
  • 2
  • 32
  • 54
valepu
  • 3,136
  • 7
  • 36
  • 67
  • 3
    As a user, i sincerely hope not. – prodigitalson Mar 04 '13 at 20:36
  • why would you want to create a pop up window with a right click, to a user that maybe a little strange.. it would make more sense with a custom content menu not a pop up! – David Chase Mar 04 '13 at 20:43
  • 1
    The popup is blocked for a reason. The user has a choice of whether to allow or deny popups and you have no control over that. – James Coyle Mar 04 '13 at 20:43
  • I need to make it so a link will bring you to two different places if you click with the left button or the right button, nothing malicious on that, it even says on the tooltip that if you click with the right button it will open a different window. The left button click is bound to an "onclick" event and it works fine, the right button click can be bound only to mouseup mousedown and contextmenu – valepu Mar 04 '13 at 20:47

1 Answers1

5

No, this is not possible.

You can see right here that in Mozilla middle and right mousebutton clicks are prevented from propagating click events. And you can see here that only click get 'trusted' and that mouseup and mousedown do not.

Chrome acts in a similar fashion, but does allow middle mousebutton to propagate click events, and they are trusted (popups originating from event won't be blocked). They will however open windows out of focus (you will stay on the current page)

I would suggest using Shift key detection on a normal click handler instead.

Jim Yarbro
  • 2,063
  • 15
  • 21
Xaekai
  • 359
  • 3
  • 9