Wednesday, May 14, 2008

Blogging Tip: Open All Links in New Window

I've been designing websites for just over 10 years now (wow!), when my eighth-grade classmate introduced me to Geocities. I quickly taught myself HTML by coding using Notepad, and to this day I have yet to find a WYSIWYG editor that trumps Notepad (though I do use the Compose window for Blogger for the most part).

Anyway, while I don't consider myself much of an expert in XML, XHTML, or CSS, I must admit I was flabbergasted when I found out the code to open all links in a website in a new window was just simple HTML.

Since as of yet, nobody has answered my question of whether or not you guys prefer me to set all links to open in new windows, or for you to make that choice yourself, I decided to follow my gut instinct and go with the former.

Since Blogger couldn't be arsed to add an option to make all outgoing links open in new windows (I still highly recommend Blogger do that, though!), I was having to edit the link html every time to add a target="_blank" tag to open in a new window. It's the only thing that was causing me to jump into the Edit Html tab to get into the code. There had to be a better way, which meant a trip to Google.

Without further ado, here's the one line of code you need to insert to set all links to open in a new window:

[base target="_blank"]


(replace the [ and ] with <>)

Just insert that within the [head][/head] tags, before the [body] tag, and you should be all set! You can edit the HTML layout of your blog and insert it and it should work (I know, it worked for me)

Related Posts by Categories



Widget by Hoctro | Jack Book

8 comments:

Anonymous said...

I found this code as well but when I tried to put it the html portion of my blog I get an error stating that the element type "base" must be terminated by the matching end-tag ""

Any suggestions?

Indo Dreamin' said...

it does not work. I keep getting the same error.

Anonymous said...

To get it to work:

put a slash (/) right before the ending >
it worked for me

Anonymous said...

Thanks a bunch for this tip. You're a real lifesaver. Before using this code, all my links had to be hand coded. A real hassle!

The code worked fine. At first, I forgot to use the
<> end caps and left the [] caps and it worked just fine with no error message.

When I tried to use the code with <> as you suggested, it came back with invalid code warning, that said:

"base" must be terminated by the matching end-tag"

I fixxed the problem by adding the code /base (enclosed by <> ) to the end of the code.

Schruender said...

Where is the [head] [head] portion that you are talking about? I see body, but don't know where exactly this should go. Hopefully someone out there still reads this...

Brablc said...

It's towards the bottom after the Footer section. Just make sure the include the / or it will come up with an error message.

Possessionista said...

Hi ! This is a great tip. I used it on my blog months ago.

Today I updated my blog template to three columns and now the [base target=”_blank”] code no longer works.

I placed it right after the "head" code, but it doesn't work. If just keeps opening in the same window.

Anyone have a tip?

Unknown said...

I believe this is the best answer for this post:
http://praveenbattula.blogspot.com/2010/06/open-all-anchor-links-in-new-window.html