Copy Writers, Bloggers & WebDevs – Forget target=”_blank”!

jQuery logo

If you regularly anchor links to external web pages, sites & blogs, chances are you don't always remember to use the target=”_blank” attribute. Even if you do, here's a cute shortcut to cut keystrokes.

I love jQuery. It's the absolute billy's walnuts! Here's another reason why.

When we think of jQuery, or Ajax, we tend to think of snazzy designer effects and usable content distribution, but it's just not as limited as that. For any web copy producer out there, here's a cracking little piece of jQuery loveliness to save you time and forgetfulness.

Setup Unmanaged VPS (4 Noobs!) ... with vpsBible
Secure WordPress. Properly. ... with wpCop, the platform's dedicated security website
Olly 'the_guv' Connelly's site and 'WordPress 3 Ultimate Security' book.

Here's the regular deal .. every time you create a link to an external site, your anchor looks something like this, huh?

And if you weren't sure, that target=”_blank” value ensures that when someone navigates a link on your page, they don't leave your page in the process. Aah, important then, huh.

And quite likely you create links several times a day, and that's a thousand times a year.

Use jQuery for target=”_blank”

If you already use JQuery – and maybe even if you don't * – never again! Just bundle this cute little rule into your jQuery.js file:-

.. swapping my domain name for yours and, with that, no more typing target=”_blank”.

* If you don't have jQuery on your site (why not?) then it's not worth doing this because your adding another file to load, weighing more that the hyperlinks. Which makes me think maybe I should write up a post with a bunch of reasons just to get jQuery anyway.

I'm Using a Plugin to Automatically Add target=”_blank”

So what does that weigh? Because plugins aren't always efficient. Maybe you're better off with this trick, linking to the jQuery library, with it's 22kB overhead .. but only really if you want to use jQuery for oh-so-much-more.

Just add this in your website's header section:-

Besides, most people have jQuery cached already, so for many visitors the jQuery's file won't even have to load.

Will target=”_blank” Work If People Have Javascript Turned Off?

Er, no! Rather depends on your demographic. Smorgasbork ran a survey last year and they summarize,

“.. 3.7 percent disable all cookies. Very few people disable javascript ..”

I guess for you, reading a piece like this, it's between trace and 2%.

Want to find out more about Javascript, and the cool-as NoScript Fiefox plugin? Read my guide Don't Get HaCkEd by Javascript – Surf Safe Anonymous Pt 4.


About the Author:

Olly Connelly (yeah, that's me) blogs at, polices WordPress security at and helps noobs build web servers at, so if you've got sleeping problems you know where to come.

Add a Comment