Saturday, February 02, 2008

Make All Links Open In A New Window

If you compose your blog, as I do, with lots of links to other blogs and web sites, you may make it convenient for your readers to view those other blogs or web sites then return to your blog. Instead of viewing the other blog or web site in the same window, you open the other blog or web site in a new window. When your reader finishes viewing the other blog or web site, he / she simply closes the new window. The article that he or she was reading, in your blog, is right there in front of them.

You can, similarly, do this with pictures. If you want your reader to view a picture, then return to the text in your article, you open the picture in a new window.

Instead of coding each individual link to a blog, picture, or web site, you can make all links within your blog open in a new window. Simply add a "<base target='_blank' />" to your blog, in the header.

Find
<head>

And change that to:
<head>
<base target='_blank' />

But, consider this carefully. If you construct your blog heavily using hypertext, as I construct my blogs, do you really want your readers having to close a window each time they finish reading a linked article in your blog? Do this with discretion.

While the reader is in your blog, give them one choice of what to read at any time. If they click on a link to read some detail, let them read the detail. Then, they click on the Back button, and return to where they left the previous article. Only if the reader is leaving your blog, to read another web site for detail, should you keep your blog open in the current window, and open a new window for the new web site.

Of course, if you have an insanely huge amount of links that you would like this way, maybe in a few linklists, you could host the linklists in another blog, and include the other blog in an iframe or maybe a series of posts linked to your public blog. Maybe including the iframe in your sidebar would work for you.

>> Top

45 comments:

cool lounge said...

thankz alot for the script, is very easy!!

cool lounge said...

thankz alot~ is very easy to do

music for soul said...

hi thanks mate, its very helpful for me, as i have tons of link i need to add target='_blank' before. you rocks man.

Thrifty Toddler said...

Thank you! I've been searching and searching online trying to figure out how to do this (I'm such a rookie). This is the only one easy enough for me to understand! :) Thanks again!

Aaron said...

Thanks for these instructions.

I implemented them successfully.

But I do have one question -- I like having most links open in new windows, but I'm not crazy about having the "Older Posts" and "Archive" links open in new windows. Is there any way to force these to open in the _same_ window? Thanks!

Sincerely,
Aaron Dalton
1GreenProduct.com

Chuck said...

Aaron,

What links do you want opening in a new window? The archives links will have to have the same policy as links in the posts.

You can make a separate blog, to contain linklists and such, and have a different policy for those links, but the blog which contains the posts and the archive links has to be the same.

Right now, I suspect, you're stuck with hand coding each individual link, to have archives and posts links work differently.

Virtuous Blue said...

OMG I tried so many tips that didn't work and your tip was quick and easy. Thanks a million!!!

Leanne said...

exactly what i was looking for! thanks :)

Matt said...

Absolutely perfect!! Thanks!

phurtive said...

Exactly what I was looking for, thank you!

Pedrofigo said...

Tx, I was looking for this, very easy indeed.

RuthWells said...

When I try this in my Blogger blog, I get this error message:

Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: The element type "base" must be terminated by the matching end-tag "".

What am I doing wrong?

Zen Tiger said...

very cool and easy as pie - thanks allot

gm said...

"Wah!! thankyou bro, susah bebenor nak cari camne nak buek natang ni... dulu dah buat tak jadi pasal silap sikit jer"

Translate..

"Wah!! thankyou bro, it was hard to find to find the coding how to make it.. last time I try but it's not working because of a litle mistake"

Adrian said...

Thanks a lot of this, it works really well!

Hobson said...

thanks for this one :)

Dipa Ghaghda said...

Thanks! Worked like a charm! would definitely recommend ur blog ;)

Bram Faems said...

Though i think it's better to add the target="_blank" manually (because not every link needs to be shown in a new window/tab) this tip helped me a lot with the website for my school.
Teachers who have little or no knowledge of html, are far better off now, then ruining my iframed website.

Thanks a lot!

Wanker said...

Thanks a lot. you are very helpful!

FabulousTerrah said...

you are amazing :)

vien said...

Thank you, yours was the easiest to understand.

Vagabond said...

Thanks for this very useful trick!

Julia Borsos said...

The code works very well for opening all links in a new window, HOWEVER there's an easy way to make only links in an article open in a new window.

I wrote a how-to aarticle on how to achieve this.

Great post btw :)
http://cyborgfrog.blogspot.com/2009/01/how-to-make-all-links-open-in-new.html

vrtulobjeq said...

Should this change work in the Preview view ?

Chuck said...

vrtulobjeq,

I wouldn't bet on it doing so, reliably. This change I would only test in a blog after published.

vrtulobjeq said...

Thank you Chuck, so how should I proceed after I publish my blog with the change and I find my blog doesn't work like it ought ?

Chuck said...

Vrtulobjeq,

I can see 2 choices for you:
1) Reverse the change (you did backup the template I hope), and find another solution.
2) Figure out what you did wrong, and correct your mistake.
Your choice, based on your priorities.

vrtulobjeq said...

Thank you for your patience Chuck.

Life Docket said...

perfect! thanks

YOGESH said...

thanks

Manish Ahuja said...

Thanks a lot. The tip is extremely useful and is extremely useful too. I've made the necessary changes on my blog .

Technologian said...

thanks a lot...

i applied to my blogs...

B.Tech ebooks and other said...

its very good


thanks for u

wroxton said...

this was helpful... your explanations are clear and easy to understand for the novice blogger

Jenne said...

Thanks for the easy explanation!

Kori said...

I tried this and got this message:

We were unable to preview your template
Please correct the error below, and submit your template again.
Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: The element type "head" must be terminated by the matching end-tag "".

I tried adding only the <{Code, apparently I can't post a comment with the correct code}> below {head} (commenting here is tough, it doesn't allow you to use any HTML code, I'm substituting parenthesis for the "<"), which made NO links click-able. I can click on anything and nothing happens. The pointer doesn't change either.

I also tried putting <{Code, apparently I can't post a comment with the correct code}> above {head}, and again, no links are clickable.

Any suggestions or ideas?
http://bubblykori.blogspot.com/

Thank you!

Chuck said...

Kori,

With the need to enter HTML, you'll be better off in an interactive forum like Nitecruzr Dot Net - Blogging. That's much better than Blogger commenting.

*Marie* said...

I got it to work on my blog with no problem. It was exactly what I was looking for. Thank you!

Victoria said...

Excellent, just what I wanted - thanks!

-BossinG- said...

thanks for the

New window tut hehe

it works

http://finally-found.blogspot.com/

koolstud said...

thanks ! great tip..I was searching for this for quite a long time.
Had no idea that it would be so easy to implement.
Finally it's working at my blog
http://requestbooks.blogspot.com

lenn0n said...

i have to say thanks for saving my times... lots of my times..!!

Conservative Brawler said...

Thanks so much for this! Very helpful!

David W. Nees said...

Thank you very much!
David

Daniel Elihu Kramer said...

Perfect fix! Thanks so much. I wonder why Google doesn't want to provide this option?