We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

kyokutyo on 02/20/08


Tagged

link window external


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

heinz1959


external link


Published in: JavaScript 


add onclick="window.open(this.href); return false;" to a Tag with rel="external"

  1. function externalLinks() {
  2. if (! document.getElementsByTagName ) return;
  3. var anchors = document.getElementsByTagName("a");
  4. var isIE = (document.documentElement.getAttribute("style") == document.documentElement.style);
  5. for (var i=0; i<anchors.length; i++) {
  6. if(anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external"){
  7. if(isIE) anchors[i].setAttribute("onclick",new Function("window.open(this.href); return false;"));
  8. else anchors[i].setAttribute("onclick","window.open(this.href); return false;");
  9. }
  10. }
  11. }
  12.  
  13. window.onload = externalLinks;

Report this snippet 

You need to login to post a comment.