Posted By

markrocky on 12/06/07


Tagged


Versions (?)

Standards Compliant External Links


 / Published in: JavaScript
 

opens links in new window, the standards compliant way, using rel="external" - for example: title="Download Adobe Reader" rel="external"

  1. function doStandardsCompliantExternalLinks() {
  2. if (!document.getElementsByTagName) {return;}
  3. var anchors = document.getElementsByTagName("a");
  4. for (var i=0; i<anchors.length; i++) {
  5. if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external") {// for example: title="Download Adobe Reader" rel="external"
  6. anchors[i].target = "_blank";
  7. anchors[i].title += " - Opens in new window";
  8. }
  9. }
  10. };

Report this snippet  

You need to login to post a comment.