0

is there any framework (jquery, or anything else) or any java script which can handle this problem:

  • if a link is clicked: open a popup
  • if somebody clicks with: middle mouse click or with right-click: open in new tab, it should open in a new tab.

I can't believe, there is no (complex) solution for it!
(and: would be nice if it's working on IE7+, FF, Safari, Chrome)

Joergi
  • 1,527
  • 3
  • 39
  • 82

1 Answers1

2

You simply need to bind a handler for the onclick event that will call window.open() to open the new window. I haven't tested in all browsers, but the ones I have tested in don't fire the onclick event when you use the middle (scrollwheel) or right mouse buttons.

HTML:

<a href="yourpage.html" class="popuplink">Click me!</a>

jQuery:

$('a.popuplink').on('click', function(e) {
    e.preventDefault(); // don't want to follow the link
    window.open(this.href, 'new_window', 'width=800,height=600').focus();
});
Anthony Grist
  • 38,173
  • 8
  • 62
  • 76