Ban target="_blank"

Today was a free day for me so I spent it browsing the web, writing posts and just general faffing around. Spending so much time on the Net today prompted me to write about one of my pet hates – web sites that open new windows when you click on a link.

First a bit of technical background for those of you that don’t use HTML. If you know this stuff already, then feel free to skip this bit. A link is created in a web page by using the anchor tag. It looks like this:

<a href=”http://www.example.com”>link text</a>

Clicking on “link text” would bring the user to the web address specified in the href part of anchor tag. (In this www.example.com). In some cases developers want the page to open in a new browser window, in which case they write the anchor tag like this:

<a href=”http://www.example.com” target=”_blank”>link text</a>

Now when the user clicks the link, a new browser window is opened to display the web page specified. It’s the target=”_blank” part of the anchor that tells the browser to open a new page. The thinking behind using this type of behaviour is that the user is not forced to navigate away from the website that spawned the new window, thereby making it easier for them to return.

However in doing so, the web developer is removing control from the user. From a Human Usability point of view, loss of user control in this way is a Bad Thing. The user should always have full control of their browser window, and removing that control will actually lead to an increased risk that they will either move on elsewhere and not come back, or will be unable to find the original site that spawned the new window. That is, it’s easier to use the back button to browse back through your history then it is to find the one window out of ten that have been opened on your desktop.

In order to ensure that websites can be properly displayed by any browser, there is an industry body that provides standards for the various web languages. This body, the W3C, is currently working on a new standard for the most basic web language – HTML 5.0.

At the moment, the current standard is HTML 4.01. In the full specification of this standard, there is no place for the target=”_blank” attribute. It’s not allowed, and technically, including it in your website breaks the standard.

The reason we still so many links opening in new pages is that there is not just one version on the current HTML standard, there are actually 3:

  • HTML 4.01 Strict,
  • HTML 4.01 Transitional, and
  • HTML 4.01 Frameset.

Only the HTML 4.01 Strict version of the standard prohibits the use of the target=”_blank” attribute, so designers can still use it by telling the browser to use one of the other standard versions. (How this is done is a bit beyond what I’m trying to get at, but suffice to say that each page on a website has to contain a Document Type Declaration which names the version of the standard being used.)

Even if the web developer specifies the HTML 4.01 Strict version and uses the target=”_blank” attribute, the browser will still open the link in a new window? Why? Because the browser doesn’t have to follow the specifications. It is up to the browser to implement the specification as it sees fit, and to try and interpret the web developers intentions as best it can. This means that although a page may not comply with the specifications, it will still display and work as intended.

This type of behaviour is not going to change any time soon. No browser is going to go down the route of refusing to display a website because it doesn’t exactly comply with the W3C standards. Few enough web developers care about these standards, and even fewer Internet users are aware that they exist. In fact, you’d be surprised how badly most of the the W3C standards are implemented in modern browsers.

So where do we go from here? As I said before, the W3C are currently working on HTML 5.0, but that in itself is not going to stop web developers from opening new windows. Even if browsers ceased supporting the target=”_blank” attribute, there are other ways to open a new browser window using scripting.

One possible solution is that the browser developers recognise that this is a bug-bear for some people and add an option to disable this behaviour within the browser. One setting that allows the end user to decide how these type of links should be handled. Thankfully with Firefox it is possible to do this, though it does require a bit of manual editing of the Firefox preferences. Here’s how:

  • Open a new tab, and in the address bar type about:config and hit enter.
  • In the filter bar, type browser.link, you should be left with 3 settings:
    • browser.link.open_external
    • browser.link.open_newwindow
    • browser.link.open_newwindow.restriction
  • Double click each one in turn and set the values as follows:
    • browser.link.open_external: 3
    • browser.link.open_newwindow: 3
    • browser.link.open_newwindow.restriction: 2

The changes should take effect straight away. This won’t completly solve the problem, as new windows will now open in new tabs instead, but at least they’ll all be contained within the same browser window.

You can test whether it works for you or not by clicking this link: Google in a new window

Tags: , , , , , ,

2 Responses to “Ban target="_blank"”

  1. James Stansell says:

    I clicked your google link in Firefox without messing with your about:config instructions and just got the google page in a new tab.

    OK, so now I pull up about:config and check what I have. The values are the same as you listed, but all show as being the default value.

  2. Paul says:

    Hi James,

    Two of the settings that I mentioned, browser.link.open_external and browser.link.open_newwindow, can be set through Firefox Preferences. (Preferences – Tabs – New windows should be opened in:)

    The third one, browser.link.open_newwindow.restriction, is not configurable from Preferences, hence the reason for setting it from about:config.

    As the post was a bit on the long side, I decided to show how to change all 3 settings from about:config, as it was quicker than going through Preferences and about:config.

    Regarding the default status, when I initially changed my settings, the status showed as “user set”, but when I checked them later on, the status was “default” – I don’t know, but it looks like that’s just the way that Firefox displays the status.

    When I first used about:config browser.link.open_newwindow.restriction was set to 1, which I then changed to 2.

    Regards,
    Paul.