Wednesday, September 7, 2011

Set all the links in your blog to open in a new window - except if you use AdSense!

You can set your blog up so that all clicked links open in a new page.  But this is not a good idea if you are an AdSense publisher - this article explains why.

Making links open in a new tab

Sometimes, you need to refer to outside material in your blog:  your ability to quote it is controlled by copyright laws, so you may need to link to an outside source, rather than quoting it in full.

Blogger's Post Editor has a tool for changing some text into a link - and it's been much easier to use since they added a check-box turns the "open on a new tab / window"  option on/of.   If you tick this option, then the post-editor automatically adds target="_blank"  (the HTML code for this) to your link.

For example
< a href=""> Blogger-HAT's Home Page </a>
< a href="" target="_blank"> Blogger-HAT's Home Page </a>

Doing it automatically

Occasionally there are requests in the Blogger Help Forum like
"How can I make all the links in my blog open in a new window" 
These often cone from people new to Blogger who, understandably, want to keep the traffic on their site.

There are ways to do this, provided you're willing to accept the disadvantages of editing your template - this explanation shows how to do it.    Although this approach works, the advice in the help-forum usually includes a warning to think very carefully about whether you really want your visitors to see a new page whenever they look at your own "about" page or one of your older posts.

Another option is to set the blog up so that only external links (ones to pages outside your own URL) open in a new window.   To do this:

  • Edit your template in the usual way.
  • Find the </head>   statement
  • Put the following code immediately before the </head> statement  - except don't add the purple line if you already have it somewhere else in your template.

<script src='' type='text/javascript'></script> <script type='text/javascript'>
$(document).ready(function() {
if(this.href.indexOf(location.hostname) == -1) {
$(this).attr('target', '_blank');
if(this.href.indexOf(location.hostname) == -1) {
$(this).attr('target', '_blank');

It's not a good idea for AdSense publishers

The approaches described above work.   But there is one issue that's often not mentioned:  the relationship between this command, and the terms and conditions of other tools that you may be using on your blog.

The last time I read AdSense's terms and conditions, it was very clear that when a user clicks on an AdSense ad in your site, the ad must open in the existing window:  advertisers are paying for your viewers full attention, not to have them still thinking about YOUR website.

I'm no lawyer, but it seems clear to me that setting your links to automatically open in new pages would be a clear violation of this.

So based on this, I would recommend that
If you use AdSense,
Then don't install auto-new-page code into your template, and check that any 3rd party templates that you use don't have this feature either.  

If this advice worries you, you may like to use an alternative advertising programme:  it seems that Chitika, at least, does let you customise your ads in this way.

It's fine to open individual links on a new page - just don't do it for all of them.

Disclaimer:  this advice is based on my interpretation of the Terms and Conditions.   Caveat emptor.  Always read the terms and conditions yourself,  every publisher is responsible for making sure that their site complies.

Related Articles

Setting up AdSense on your blog

Alternative advertising programmes

Copyright, blogs and bloggers

Advantages and disadvantages of editing your template

Extra customization of Chitika ads

Other tools you may like to use on your blog

Share this Article


HTML link code:

BB (forum) link code:

Subscribe to Blogger-hints-and-tips

FeedBurner will send a confirmation message. Click the verify link in it to start your subscription.

Follow Me on Pinterest Subscribe to Blogger-HAT on Google + RSS subscription icon Follow BloggerHAT on Twitter


  1. Thanks, this helped alot, and was easy to understand!

  2. Yes Interesting I had not thought of that at all.

  3. The LINK at the end of "Another option is to set the blog up so that only external links (ones to pages outside your own URL) open in a new window - one way to do that is described here " goes astray

    1. Thanks for letting me know, it seems that the external site I was pointing at is now longer operational. I've updated the post with new information.