Posting at the Alliance, phin mentioned the tip, while Cory of Core|Blog mentioned using the value "_blank" for the attribute "target" when writing links.
For example, if you wanted to write a link that linked to this little blog, you'd normally do it this way:
<a href="http://www.basilsblog.com/">Visit basil's blog</a>
If, however, you wanted the that same link to open a new window (or, if you use a Mozilla browser such as Firefox, Opera, Netscape 8, or Mozilla Suite browser, open in a new tab), you'd change the link to look like this:
<a href="http://www.basilsblog.com/" target="_blank">Visit basil's blog</a>
The difference, you'll notice, is the target="_blank" part. Of course, you need to be able to edit the HTML of your post, or your interface would need to have the ability to add a target.
That's essentially what phin and Cory suggested. And it works. But it's not how we're doing things here at this little blog.
Suppose you find that you want most of the links to open that way. That is, suppose opening in a new window/tab is the norm? Suppose it's only sometimes that you want to open in the same window?
Well, that's how I have this little blog set up. I don't have to put target="_blank" on my links, because that is the default I use. How is that done? Well, it's easy. But there's always a catch.
Changing The Link Default
In order to make links, by default, open in a new window/tab, you need to be able to edit the HTML of your blogging template. If you use Blogger, that's easy to do. If you use TypePad, it's a little more involved. If you use WordPress or another blogging system, see your documentation on how to edit your Template.
A word of caution: if you're not sure how to edit your Template, you probably don't want to.
Now, to set "_blank" as your default target for your links, open the Template (or Templates) for editing. In the <HEAD> section place the following line:
<base target="_blank" />
You can put it anywhere in the <HEAD> but it's commonly placed just above the closing </HEAD> tag.
And that's it! That's all you need to do make the default links open in a new window/tab.
But There's A Catch
Okay, that's not all there is to it. Oh, yes adding that line of code to your Templates does indeed make all links open in a separate window/tab by default. But think about that for a second.
All links open in a separate window/tab. All links. All.
And all means all. All.
Think about that.
If you are on the main page of your blog and you click on a link to, say, read comments or something, it opens in a new window/tab. And that's probably not what you want.
Here's my thinking, which might not be the same way you'd think:
- If the link is to another page on my blog, I don't want it to open in a separate window/tab. I want it to stay in the same window/tab.
- If the link is to a page on another blog/site, then I do want it to open in a separate window/tab.
So, let's assume that's how you want to do it, too. How do you make that happen?
Overriding The Default
Once you've changed the default to open links in a new window/tab, you need to make some more modifications to your Template.
Look for all the links in your Template that refer to another page on your blog. For example, the "permalink" on each post allows you to open just that post. You'd need to modify it to open in the same window/tab, not the new default. To do that, add target="_self" to the link.
For example, if you use Blogger, you probably have a line that looks something like:
<a href="<$BlogItemPermalinkUrl$>" title="permanent link"><$BlogItemDateTime$></a>To make it always open the same current window/tab, you'd modify it to:
<a href="<$BlogItemPermalinkUrl$>" title="permanent link" target="_self"><$BlogItemDateTime$></a>You see what we did? We simply added target="_self" to it. You'd need to do that for every link in your Template that refers to another page on your blog. Don't forget the "Home" page link.
Once that's done, your Template is done. After you republish, your blog now opens all links in new windows/tabs, except the standard links to other pages on your blog.
Oh, One More Thing
But, what if you write a post that includes a link to another post on your blog? You probably don't want it to open in another window/tab. So, you'd include target="_self" in those. Do it manually, for each link in a post that should open in the same window/tab.
Essentially, it's the opposite of what phin and Cory suggested. Or, it's the extreme of what they suggested. Whichever way works for you.
And, in case you haven't noticed, it works for me.
And One Thing I Forgot To Mention