I lost all my content when the blog got hacked and my hosting company could not restore it. I have subsequently unearthed a heap of old posts (that had synced to Facebook as Notes). It’s really interesting (and quite funny) to see what I was busy with so many years ago!
In this post:
Required knowledge:
1. Standard’s complaint code
As more and more sites strive for standards-compliant code that passes validation, the developer now faces a conundrum: the once simple process of adding the target
attribute for links opening in a new browser window or tab will not validate.
You do NOT want a visitor to click away from your site. It took all kinds of wizardry (or hard cash!) to get the user to your site, and now you want to keep him/her there.
2. target
The traditional method was to use the target
attribute of the tag, for example:
<a href="www.anotherdomain.com/page.htm" target="_blank">Click me</a>
This, however, will not validate as HTML 4.01 Strict or XHTML 1.0 Strict, as the target
attribute is deprecated in both. If like me, you have opted to start coding standards-compliant code, this presents a new challenge: how do I stop my visitors from “clicking away” from my site?
3. Differentiate
Let’s differentiate between links here:
- Links that form part of your site’s navigation
- Links to resources within your site (images, PDF’s, etc)
- Links that lead to external pages or resources
In the case of links in the first class, as you are surely not using frames (!!), there is no real need for these pages to open in a new window or tab — in fact, quite the opposite. As such, they should visually form part of a navigation structure (navigation bar, breadcrumb navigation), thereby implicitly indicating that the link is to another part of the same site. I think users are used to this idea.
In the instance of links that fall into the second & third classes, there needs to be some indication as to what the link is. If it is a link to a PDF, for instance, you could use CSS to style the link with a specific icon (working on an example — WordPress is not playing ball). Links such as these generally do not form part of the formal navigation structure and are therefore visually different from such links (you could use some CSS here to style your links).
4. JavaScript
You do of course have the option of using unobtrusive JavaScript to open the link in a new page.
I have heard of users setting their browser to open ALL links in a new tab when clicked!
5. Educate
The solution I believe boils down once again to educating the user to either right-click on links that do not form part of the site’s navigation, and select Open in New Tab, or centre-clicking or clicking with the scroll-button on the mouse (if they have one).