Is there a way programmatically, or via mod to cause all links on your site that point to any outside domain name to open in a new window? I have read through the entire mod library a few times but don't remember seeing this specifically, of course that doesn't mean that I didn't just miss it.

Thanks,
David

Comments

benthere’s picture

If you don't mind a little programming, check out URL Class. That filter module applies CSS classes to all external links to content, but you may be able to modify that module to make your own that changes the target instead of the class. Note that this would only work for links within content, not all links on your site, such as menus.

--
Cheap, reliable Drupal hosting: 200GB | 2TB
Save $75| DH75OFF coupon for 1 year ($3.75/mo!)
Save $50| DRUPAL50 coupon for monthly ($10/mo!)

akayani’s picture

Serious web developers do ‘Strict’. This was problematic as using “_blank” is not part of the ‘Strict Specification’.

Problem solved using JavaScript as per the method outlined by on Sitepoint (Yank 2003).

http://www.sitepoint.com/article/standards-compliant-world


For the link...

<a href="here/filename.xxx" title="My Title" rel="external">
<img src="images/icon.png" alt="whatever" width="xxx" height="xxx"  title="xxx /> </a>

<!-- note the rel="external" tag -->


// JavaScript Document

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

That's been my approach.

Yani

ufku’s picture

<script type="text/javascript">
var lnk, lnks = document.getElementsByTagName('a');
var host = location.hostname;
for (var i=0; lnk=lnks[i]; i++) {
  if (lnk.href.indexOf(host)==-1) {
    lnk.setAttribute('target', '_blank');
  }
}
</script>

this should be inserted at the end of a page or run as a load event.

--
Geneticists from METU