views:

62

answers:

5

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>
+5  A: 

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.

Nick Craver
It opens in both new tab and new window in Firefox now :P
Richard Knop
@Richard - It doesn't in my test page...did you remove the `return false` by chance?
Nick Craver
upvote for defenestration through a pop-up window
Jonathan Fingland
No. Try it in browser, no in that application. It's probably bugged. In Firefox it will open both a tab and a new window.
Richard Knop
@user view point - I don't care about it. It is an extremely internal intranet application and it is absolutely neccessary that certain links open in a new window.
Richard Knop
@Richard - Here's that version: http://jsfiddle.net/jS7Bb/embedded/result/ You must have something else going on, it really has no reason to do that, then `return` false should prevent it, add an alert after `window.open()`, does it fire, or do you have a syntax error on that line?
Nick Craver
Another problem. The window is not scrollable. When content is too long I am not able to scroll down.
Richard Knop
@Jonathan - It was correct before `|=` is an attribute-contains-prefix selector: http://api.jquery.com/attribute-contains-prefix-selector/
Nick Craver
my bad, the original was not only correct, but also behaves as expected. Richard, I don't get the new tab + new window behaviour, either
Jonathan Fingland
Yeah, I went to revert it when I realized that it was intended. you already beat me to it
Jonathan Fingland
@Richard - There's a `scrollbars` option, check the documentation link at the beginning of the answer, it works like this: `window.open(this.href, "myWindow", "width=800, height=200, scrollbars=yes");`
Nick Craver
I have included my entire js file in my question.
Richard Knop
@Richard - **Both** of those event handlers will run for `rel="external-new-window"`, you need `[rel=external]` and `[rel=external-new-window]` to have exact matches, otherwise *both* will run on the latter.
Nick Craver
Oh, wait a second i think I see where's the problem.
Richard Knop
Ok I fixed it (see my question). Thanks very much :)
Richard Knop
@Richard - Welcome :)
Nick Craver
A: 

Set the target attribute to _blank and don't return false.

$(document).ready(function() {
    $('a[rel|=external]').click(function(){
        $(this).attr('target', '_blank');
    });
});
Teja Kantamneni
A: 

use _blank

example

window.open(this.href, '_blank');
onClick="window.open('http://www.functionx.com/javascript', '_blank');" >
A: 

window.open() syntax:

window.open(URI, window name, parameters);
  • URI: Location as string
  • window name: A unique identifier, only characters allowed are [A-Z,a-z,0-9,_]
  • parameters: height, width, left, screenX, screenY, etc. etc.

example:

window.open(this.href, "unicorn", "width=400, height=600, screenX=100");
jAndy
A: 

if ff is configured to open new windows in tabs you can not open a new window, but instead a tab.

Ionut Popa