How do I make links open a new window?

I don’t think that putting target="_blank" is trying to control the browser. Well, I do, but more or less everything in HTML tells the browser to do something, or else there’s no point to it. It’s nowhere near as intrusive and presumptuous as, say, resizing the client window, hiding the toolbars or spawning unsolicited popups. When a browser opens a link in the same window, it’s still been controlled.

I suppose in an ideal world, everyone would make the perfect choice about how to open a link, and their browsers would equip them with easy and intuitive tools for doing it any way they wanted - but we just don’t live in that world - instead, we have users who click a link, then close the window when they have finished reading it, then get very perplexed when they can’t get back to where they were beforehand.

I’ll just add that an “outlink” icon with “opens in a new window” ALT text is a good user-friendly device to warn the user that this is the intention of the link (in a perfect world, though I confess I don’t have the human or technological resources to implement this fully on any of the 20+ sites I run).

Oh come on! If you use something like NoScript you have to expect lots of stuff not to work. That is not the web designers fault, it your fault for being paranoid. You are already alienated.

WRT the other debate here, I use Firefox and I habitually middle click most links to force them to open in a new tab, in case the webmaster has not been smart enough to use target="_blank". What annoys me is when a link is done with JavaScript so that it can’t be middle clicked. (There used to be an extension to handle this called Smart Middle Click, but it seems to have died a few Firefox versions ago.)

Incidentally, I know of one site that seems to be pretty keen on being standards compliant in most respects (it uses XHTML transitional, anyway) but that insists on target=“other” instead of target="_blank". It seems to work. Is this in any standard, and are there circumstances in which “other” will have a different effect to “_blank”? Is it perhaps that any old gibberish in the target attribute will work, so long as it does not have a defined meaning? Could one use target=“MXYZPQ” and have teh browser open a new tab or window?

I’ll grant that is idealistic; but in my opinion, what is the point of having defined standards and then not striving to meet them? In my research on this topic, I’ve found plenty of articles on both sides - both make opposing claims about what “the majority of users” do, but none can provide any evidence. Can you?

I think this is the crux of our disagreement; I don’t feel it is correct, nor optimal, to cater to the lowest common denominator in this case as it just perpetuates the problem.

Actually, if you review the list of HTML elements I trust you will find that the minority of them actually “do” anything. The purpose of HTML is to provide semantic description of the content. It is the user agent that then interprets this information and decides what, if anything, to “do”.

No, when a browser opens a link in the same window it is taking a default action; as the user I can control whether the link opens in another tab or another window. By forcing the link to open in a new window, you’ve taken away that control.

This is good practice, and actually recommended by the W3C until such time that browsers allow us to optionally ignore the target attribute.

Do you honestly feel that using add-ons like NoScript of AdBlock means one is paranoid?

And by not smart enough you mean they have a preference for following clearly defined web standards and allowing their visitors more control of their browsing experience, right? Right?

From the HTML specification:

So, in short - yes.

Yes, it does annoy me when links don’t do what I expect, and what I expect is that they replace the content in the current window/tab, because that is the long-standing standard behaviour. If the link clearly indicates in some way that it will open in a new page, I’m OK with that. But otherwise, it’s like the site’s designer is saying “I know better than you how you want to view the link”. Marketing people in particular always seem keen on this link behaviour, because they don’t want users to navigate away from their precious pages.

So thank god for Tab Mix Plus - it allows you to override web designers evil intentions and make links behave like you’d expect.

Who mentioned AdBlock? In the case of NoScript, unless one is out there deliberately seeking out attack sites or something, yes, I think it is rather paranoid. And it is certainly silly (and selfish) to expect sites to avoid using JavaScript just to pander to the tiny minority who use NoScript.

Hey man, be cool, its just web design.

But yes, is I think what jjimm and others are saying about user friendly web design in this thread is smarter than what you are saying. I prefer it his way, and it appears that quite a few others do too. I am sure not everyone prefers it, but you can’t please everyone. The aim should be to please the majority.

Didn’t BBC just have a programme celebrating 20 years of “the Internet”? One which crashed their website when viewers went to fill in a poll, as requested at the end of the show? :smack:

I use NoScript not because I’m worried about malware, but because every now and then a script seems to max out the CPU and bring Firefox to a standstill. So I prefer to allow scripts only from whitelisted sites.

Your quote was “something like NoScript” - which, along with NoScript, is one of the more popular add-ons. And at no point did I say that JavaScript should be avoided to pander to a minority. It is the developer’s responsibility to ensure that their site(s) degrade gracefully if/when JavaScript is not available to the user - whether it be because they’re using a screen reader, have JavaScript disabled, or are in fact not human.

It’s one thing to have an opinion, but another altogether to claim that anyone who disagrees with you does so because they are “not smart enough”.

I certainly don’t have anything like that up my sleeve. All I can say is that I try to apply common sense when I’m formatting links. For an external link in the middle of a page, I don’t think it’s even slightly unreasonable to assume that my visitors will probably want to open it for reference, but continue to read the rest of the page, after the link. I don’t see this as being any different (in any sense meaningful to the visitor) than me imposing my choice of layout or colour scheme upon their eyes, or imposing my choice of category navigation, etc.

But if doing the technically correct thing (assuming we can agree what that is) annoys the majority of your site visitors, is it still a good idea?

We probably just have different defintions of ‘do’ here. When the browser renders a page, it’s doing something - when it opens a link in the same window, it’s doing something. shrug

If that disrupts the experience of those users who don’t know how to control it for themselves, what’s the solution?

Are there no situations in which you would consider it entirely appropriate for a link to open in a new window? (possible candidates: product description or T&C links when you’re at step 4 of 5 of an online store checkout)

Do you know of any simple way to style this? (i.e. without having to explicitly code a default link plus an out-linked graphic as separate bits of HTML)

I learned this as target=“X”, so presumably whatever nonsense you put in there works equally well. HOWEVER, I would like to throw my hat into the “don’t effing do this without an ‘opens in a new window’ warning on the link” pile. *Especially *don’t do it if your target demographic can be assumed to be reasonably conversant with browser features (e.g., teens through early 40s, versus, say, seniors).

If you want to add a graphic to links that contain target=’_blank’:



/*
- change 'right' to 'left' on both lines to have the icon appear to the left
- adjust pixels of second line to accommodate width of icon being used
*/

a[target="_blank"] {
    background: url(images/external-link.png) no-repeat scroll center right;
    padding-right: 10px;
}


If you’re not using target=’_blank’ in your HTML, you could use Javascript to loop through all links and add target=’_blank’ to external links (by checking the value of href for “http”, for example).

Cool - thanks for that - if I understand it correctly, that’ll add a graphic to any link that pops (and that’s good - I’ll probably use it soon) - what I would really like to do would be to be able to define a single style that lets the link itself open the way the browser wants to, but clicking the graphic makes the link pop.

I can obviously do that by coding the link and graphic separately in the HTML source, but can it be done in CSS to style a single link?

The use of HTML to open links in new windows has been deprecated. You should use JavaScript to make links open in new windows.

Try this from Dynamic Drive

You mean like here at the Dope, where all links in a thread open in a new window?

Opening alternate, non-site content in a new window has been the default - and IMO, the only acceptable option - for so long that I’ve forgotten when it started.

As for user understanding: 50,000,000 people have started blogs. At last count 19 of them know how to go into the template and change the source code as given above.

The world is divided into 10 groups. Those who understand coding and think that everybody in the world should conform and the other 99.9% who don’t want to know anything about it and just want to sit down in front of their computers.

Yes, like that. It irritates me that you have to stop and think “wait, is this going to replace the page or open a new one?” Seems like fundamendtally bad UI design to have the same operation do different things depending on some vaguely defined rules.

Of course, in practice you get used to the behaviour of sites such as the SDMB, and you can use middle-clicking and browser add-ons to control link behaviour, as mentioned above. Perhaps it’s not that big a deal, because the sort of people who are bothered by it tend to be relatively sophisticated users who will go to those lengths.

I think there is an increasing tradition that links within a blog post or a messageboard post will automatically open in a new window, and other links will not (unless accompanied by an “external link” symbol like on Wikipedia). If that tradition is maintained, then it will become the expected standard.

I generally assume that all links are going to be internal, and “middle click” (or ctrl-click because I don’t use a mouse), except in the aforementioned cases. If either do not behave in that expected way I do get a little annoyed.

In general, JavaScript based links that open a new window are the worst of all possible worlds. They will not satisfy those who think links should open in the same window by default; they will not satisfy those who like to use NoScript or similar;* and they will not satisfy people like me who like to use middle-click to ensure a new tab, or even those who like to right click and choose an action from a menu.

If this is truly the recommended standard now, then the standards committees must be full of idiots.

I should admit that the quite complex script that you link to does avoid these problems, although at the cost of making users deal with an otherwise unnecessary and probably confusing checkbox, but that is not what “using JavaScript to make links open in new windows” usually means.
*Apparently I need to spell out that by this I mean other ways of blocking script execution; I do not intend it to refer to other sorts of blocking extensions such as AdBlock.

Tradition, maybe, but I don’t think it has reached the level of de facto standard yet, and as a result link behaviour is inconsistent from site to site. Wikipedia, as you mention, denotes external links with a special symbol - but those links open in the current window, not a new one.