Jon
Rohan

I'm a front end web developer living in San Francisco. I have been coding HTML since I was 15. I strive to be the best I can at what I do. I believe in clean and simple design as well as code. This is where I represent myself on the web. I am always looking to form relationships with other amazing people, part time or full time. contact me!

jQuery Snippet for Opening all External Links in new Windows

This is just a quick share, but while developing my site, I realized I don’t want visitors to click on a link and be taken away from my site. The proper way to do this is to add the target=”_blank” to all your external links like so.

<a href="http://www.deltatangobravo.com" target="_blank">design</a>

But I’m way too busy to remember to do that for every link I add to my blog. I mean I try to but what happens when I forget. So I wrote a small jQuery snippet to get my back.

$("a:not([href^='http://www.dinnermint.org']):not([href^='#']):not([href^='/'])").attr("target","_blank");

It looks for all links on my page that do not begin with my domain www.dinnermint.org and adds the attribute target=”_blank”. Laziness FTW!

Tags: , 13 Aug 2009

About the Author, Jon Rohan

Hey! Thanks for stopping by. I love posting new topics here about various development things. If you liked it follow me on twitter and let me know.

Subscribe to Posts

Add comment