SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    External links script from SitePoint not working

    Hi, I searched the forum for other posts about this, but none of them seemed to contain info to solve my problem. My site pages are now html4/strict so I used the "function externalLinks" script found here http://articles.sitepoint.com/print/...ompliant-world. I followed the instructions carefully, made sure I copied the script shown to the external.js file and uploaded it into the same directory as the html files. Also made sure that external.js was called as required in the head. Also made sure all target="_blank" were changed to rel="external" as required. Unfortunately, it doesn't work. The link takes the visitor outside my site, instead of creating a new window. I don't get it. Here's one of my pages ...
    http://www.keithpurtell.com/kthings/bj-cole.htm

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,592
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Your script isn't quite the same as the code in that article:

    Code:
    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;

  3. #3
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ralph.m -
    I'm not exactly sure how I mangled the original script, but your anchor.target = "_blank"; makes my new-window links work perfectly!!

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,592
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Heh heh, great. But it's not mine, as such. I just copied it directly from the article.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •