Reliable Answers - News and Commentary

Offsite Links In a New Window

The Principle

Some clients just absolutely demand that links to other sites should open a new window, in order to provide external links, while also keeping their own visitors on their site. The method typically relied on to do this is to add a target attribute to each individual link. That method has two flaws:

  1. Manually managing every single link is time consuming, while automating the process introduces potential errors (such as duplicate target attributes) which could break code validation or could break the links themselves.
  2. There is SEO value to direct linking to external sites. While contemporary search engines are primarily link counters, there are a number of patents that insinuate certain values to links based on their attributes, including the link target attribute. If your content is intended to link to a site and pass search value to it, you should consider not including a target attribute in order to preserve as much link juice as possible.

Back to the point. The code here simply enumerates every anchor on the page and adds target="_blank" to each link that goes to a domain other than the active one.

While you could add this script to the specific pages you want to affect, it's easiest to simply add a script tag to a script with the following contents:

The Code

/*
 Shawn K. Hall
 http://12PointDesign.com/
 Copyright (c) 2004,2010
*/

function blanky(){
// remove trigger
  try{
    window.clearInterval( blankyt );
  }catch(e){};
// set external links to new window
  var c = document.links;
  var d = document.domain;
  for(var a=0; a<c.length; a++){
    if(c[a].href.search(d) == -1)
      c[a].target = "_blank";
  }
}

var blankyt= window.setInterval( "blanky()", 3500 );

If you are using a script tag, you'd use something like this:

<script src="/scripts/blank.js" type="text/javascript" ></script>
[CodeShare] - learn and discuss development for a P2P source-code sharing framework

Take me to the top

Your Ad Here?

Contact our Marketing department for information about advertising on this domain.


Take me to the top

We invite you
to visit:

Professional Web Hosting and Design Services: 12 Point Design Local Homeschool provides the most up-to-date support group listings in a geographical and searchable index Budget Homeschool Kidjacked -- To seize control of a child, by use of force SaferPC dispels security misunderstandings and provides you with a solid understanding of viruses and computer security Reliable Answers - developer information, current news, human interest and legislative news Twain Harte Photo Gallery - Twain Harte, CA - The closest you can get to Heaven on Earth Cranial Laser & Neurolymphatic Release Techniques (CLNRT) - Experience dramatic pain reduction At Summit Chiropractic our mission is to improve your quality of life - We know that health is much more than just not feeling pain Visit UniveralPreschool.com to learn about your preschool options. Dave's Quick Search Deskbar
Reliable Answers.com/js/offsite_links_in_a_new_window.asp AddThis Social Bookmark Button
Google