Accessible ways to open a new browser window

Personally, I’m not keen on forcing a new browser window to open on the user. It takes away user control. Users should have the right to decide if they open a new window or not.

Most people now, especially with the rising popularity of Firefox and Internet Explorer 7, are familiar with tabbed browsing. If they want a new window or tab they’ll right click and open a new window or tab.

So what’s the problem?

Well, sometimes it is necessary to force the opening of a new window. For example, a third party application that “integrates” with your website may need a new window to be opened in order to preserve the user experience and aesthetic appeal.

This is a scenario local government websites and probably many legacy website face. A third party application is brought in and rolled out that looks nothing like the main website except the company logo that is placed in the header.

That’s the fully integrated web application as promised by your supplier.

This is a case where you would want to force a new window to open.

How to open a new window

Be nice, warn users that a new window is going to open.

It is only polite.

Using text such as “Opens in a new window” in the link text tells the user exactly what is going to happen.


This does look very good though, does it?

Well, you could put “Opens in a new window” in the title attribute. However, this will not help visual users who use the keyboard to “tab” around the website. No modern browser displays the text in the title attribute as a user tabs through web page content with a keyboard.

HTML 4 doctype

If you are still using a HTML 4 doctype you could use the target attribute of the anchor tag.


Bish, bash, bosh and you’re done. No JavaScript needed. Perfectly valid for your doctype.

XHTML doctype

Most people now, I like to think, are using an XHTML doctype. The target attribute is no longer an option if you want your page to validate to W3C standards.

Using JavaScript to open a new browser window

There are several blog posts and forum discussions about using non-obtrusive JavaScript to open a new browser window.

These can be found at:

Reading through the various posts and discussions I favour Roger Johanssons method.

He shares a similar view about opening new browser windows.

“Opening new windows should almost always be avoided. There are very few exceptions to that rule. However, sometimes it is beyond your control as a Web developer to enforce that. You can normally choose which DOCTYPE to use though. I prefer using a strict DOCTYPE, which does not allow the target attribute. And that is why I created this script. It can also be argued that opening new windows is behaviour, and as such should be moved to the behaviour layer (JavaScript) anyway.” - Roger Johansson

It’s a piece of non-obtrusive JavaScript that kicks in when you specify


on the anchor tag.

It adds text “opens in a new window” to the link text.

Then, not surprisingly, it opens the link in a new window.

What if JavaScript is not enabled?

If JavaScript is not enabled it just displays the standard link text and opens normally without opening the new window.

You might think that


is better as it doesn’t need JavaScript to work but it now deprecated, gone, left the building, dead.

In the words of Andy Clarke, “No one dies”.

Again, here is the link you’ll need

Opening new windows with JavaScript, version 1.2