Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery open link in new window with small dimensions (NOT TAB)

I need to open certain links in a new window (NOT TAB) with certain dimensions.

This will open a link in new tab:

$(document).ready(function() {
    $('a[rel|=external]').click(function(){
        window.open(this.href);
        return false;
    });
});

What to change in order to get links opening in new windows.?

EDIT: This is my entire javascript file:

$(document).ready(function() {
    $('a[rel=external]').click(function(){
        window.open(this.href);
        return false;
    });
    $('a[rel=external-new-window]').click(function(){
        window.open(this.href, "myWindowName", "width=800, height=600");
        return false;
    });
});

HTML:

<a href="/clientarea/utils/law/id/2832" rel="external-new-window" class="accessible-link">§5, odsek 2</a>
like image 238
Richard Knop Avatar asked Jul 13 '10 11:07

Richard Knop


1 Answers

You can pass dimensions to window.open() for this:
Edited for updated question: notice the [rel|= changed to [rel=.

$(document).ready(function() {
  $('a[rel|=external]').click(function(){
    window.open(this.href);
    return false;
  });
  $('a[rel=external-new-window]').click(function(){
    window.open(this.href, "myWindowName", "width=800, height=600");
    return false;
  });
});​

You can test it here, the dimensions being different from the tab is the key here. Keep this in mind though, it may still open in a tab, there are plenty of browser options, extensions and plugins specifically to prevent popup windows.

Also, from the user point of view, too many popup windows will encourage me to hunt you down and stab you in the eye with a salad fork and/or pop-up a window and throw you out of it, so please use this sparingly.

like image 85
Nick Craver Avatar answered Oct 04 '22 21:10

Nick Craver