RSS feed
<< Notepad status bar | Home | Ultrafineonline service >>

Set TARGET to _blank

This little javascript sample will set the target of all foreign links to _blank.

<script type="text/javascript">

function target() { 
  if(!document.getElementsByTagName) {
    return; 
  } 

  var anchors = document.getElementsByTagName("a");
  var e = document.getElementsByTagName("base");
  var base = null;

  if( e.length ) {
    base = e[0].href;
    base = base.substring(0,base.indexOf(":", 5));
  }

  if (base==null) {
    return;
  }

  for( var loop = 0; loop < anchors.length; loop++ ) { 
    var anchor = anchors[loop];
    href = anchor.getAttribute("href");
    if( href && href.indexOf(base)<0) {    
      alert( "["+href + "][" + base+ "]")
      anchor.target = "_blank"; 
    } 
  } 
} 

</script>
Tags :



Add a comment Send a TrackBack
Home