New Window

From CSS Discuss

Jump to: navigation, search

Opening a new window upon clicking a hyperlink is a common technique that allows (some say forces) a user to view new content in a separate window, while keeping the original content open.

This is sometimes advantageous to the user, because the information opened in the separate window makes less sense out of the context of the original document. It can also be advantageous to the author because users following the link are less likely to "forget about" the original document.

Note that this page is Off Topic, but it is still a Wiki:Good Thing, so it remains.

Note also that this is another topic over which a minor Holy War rages. The gist of it is this: some say that it is bad to foist a new window opening upon the user, and that in most browsers, she is perfectly capable of opening a page in a new window herself as she sees fit. Plus with browsers that use tabs (Mozilla and co, Opera, etc.), most users will prefer to open pages in a new tab. Again, forcing a new window can annoy the user.

Don't...

Many authors, in implementing links which open in new windows, will do something like this:

<a href="javascript:window.open('http://www.example.com')">www.example.com</a> 

Or:

<a href="#" onclick="javascript:window.open('http://www.example.com')">link text</a> 

The downside of these approaches is that it requires client-side scripting to allow the user to view the information. In an effort to make the site more useful, it is possible to actually harm the audience's use of the site.

Do...

Instead, try this:

<a href="http://www.example.com" onclick="window.open(this.href,'newwin'); return false;">link text</a>

This approach has the benefit of allowing the link to be traversed, even if client-side scripting is disabled. The only degradation of the disabled script is that the new window will not be opened.

Related reading:

 Lon Kraemer
 Scott Andrew Le Pera

Opposing viewpoint:

  Dont Open New Window 

What's wrong with doing this? - Tar Quin

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

As far as I'm aware target="_new" was never standardized, but beyond that, the approach is roughly comparable to the Do suggestion above.


(goes off to check..) Ah. My old Netscape HTML spec says "_new". My HTML 4.01 spec from the W3C says "_blank". -- Tar Quin


In HTML 4.01 Strict the target attribute no longer exists. If you want your HTML to be compliant in the future you can no longer use target="_blank", target no longer exists in any form. See w3.org


I still use transitional HTML 4.0 plus DHTML to HTML 4.01, and in using what was termed a Netscape-friendly scroller using a layer and ilayer, I ran into the problem of offering the page in a new window. I just linked the bottom of the page that linked into the scroller with TARGET="_top".(back to 4.0)

HTML 4.0 is buggy and shouldn't be used. DHTML is a term so vague that it is useless. layer and ilayer are not part of any version of HTML, and are only supported by a single, ancient and obsolete browser and likewise shouldn't be used. Using _top as a target has nothing to do with opening new windows

Thanks for the advice on HTML 4.01, really- but, are users ready to right-click into a new window from every walk of life?

There are other ways to open a link in a new window (like a single middle click).

A good fer instance- I am making a photo essay, and I have to use a no-right-click on my page to guard the use of fairly sensitive shots from being mangled into ad graphics.

No right click scripts are as effective as protecting images as a soggy Kleenex hung across a keyhole is at protecting against entry. They annoy people, but don't provide any security. Preventing people from choosing to open a link in a new window is an example of being annoying (likewise the bookmarking and other issues)

So, fro

Personal tools