Posted By

Krummelz on 02/10/12


Tagged

links external rel


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

appeltauer


Javascript open links in a new window, without _blank


 / Published in: JavaScript
 

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

Usage: <a href="http://www.whaterver-your-site-is-called.com/" rel="external">Some other site</a>

  1. function externalLinks() {
  2. if (!document.getElementsByTagName) return;
  3. var anchors = document.getElementsByTagName("a");
  4. for (var i = 0; i < anchors.length; i++) {
  5. var anchor = anchors[i];
  6. if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
  7. anchor.target = "_blank";
  8. }
  9. }
  10. window.onload = externalLinks;

Report this snippet  

You need to login to post a comment.