1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

Identifying link targets with CSS

So, you have links that open in new windows, and links that open in parent windows. Inconsistant behaviour is the primary usability nightmare, and your standard web browser doesn’t give you any feedback on just what is going to happen once you click that link. Popups galore? or damn-I-was-reading-that syndrome? If only there was some visual clue we could give about those pesky link behaviours.

Well, this isn’t something I’ve seen anyone do yet, but technically it should be possible. What we should be able to do is transport the same techniques we use for detecting file types – ie. the CSS 2.1 attribute selectors – and link them to the target attribute. Thankfully, this should be a pretty short bit of code, as there’s only really four target options that anyone uses anyway. These would be ‘_blank’, ‘_self’, ‘_top’ or ‘_parent’. So, working on our existing knowledge of detecting link file-types, we simply add the code;

a[target='_blank']

… and we should now be able to automatically attach icons to those links that target a new browser window. (_parent, _self, and _top nearly always open links in exactly the same window) Links to other websites already have a standard icon – pretty much set by wikipedia – but it’s not often that target-based links are seen, so there’s not much of a standard. Or is there?

Sitepoint has a short article on the problem of link targets – ‘Beware of Opening Links in a New Window‘ and also has a pretty simple icon to use for new windows. Perfect! Just like internal links don’t have an icon, and external ones do, so only links that open a new browser window should need this icon. Save the icon to your webserver, add your new CSS, and you’re away.

2 Comments »

  1. need help. i have a problem to link a file to open in the window. When i set the target to _parent or _self it opens a new window. Please note that a am using css template. I need urgent help.

    Comment by HAARY — 10 March 2008 #

  2. HAARY – does this happen on more than one computer – Only “_blank” should open a new window, maybe the browser settings are overriding the html behaviours?

    Comment by Mike — 11 March 2008 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Note: This post is over 2 years old. You may want to check later in this blog to see if there is new information relevant to your comment.