External Links in A New Window

One of my friends was talking about how they wanted links to open up in a new window so that people wouldn't have to leave the website to see the pages. Not that uncommon of an idea, but the method that was being used for it was a bit overkill.

This post mentions that you can use the <base target='_blank'> to make all links open in a new window. The big with that is that ALL of your links now open in a new window, not only the links that are external links. Makes for a lot of windows/tabs if you are browsing the site a bit.

I was thinking that it would be better if you could inspect each of the links and determine if they should be opened in a new window or not. But I also wanted to support multiple types of links, such as ./, /, //, http://, https://, etc.

So I did a little morning exercise and this is what I came up with:

Posted on 5 Feb 2011