Open Link in New Window


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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") &&
  7. anchor.getAttribute("rel") == "external")
  8. anchor.target = "_blank";
  9. }
  10. }
  11. window.onload = externalLinks;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.