Kangry.com [insert cool graphic here]
home | Topics | Logout | Search | Contact | ?? Kangry ?? | Bandwitdh
Topics:
DVR
nvrec
Mplayer
Links
Misc
Commands
Humor

Name

Password

New user

uploaded files
(blogware)-> show sources DHTML code submited by Russell Wed 21 Dec 05
Edited Fri 23 Dec 05
Web kangry.com
I just added a link to the display pages called "show sources". What this does is read the links on a page and if the link contains an extra field called source it adds a link after the refrenced link to the source of that link. I do this with a bit of javascript:

function show_sources() {
     if (!document.getElementsByTagName || !document.createElement ||
!document.appendChild) return;
     var quotes = document.getElementsByTagName("a");
     for (var i=0; i<quotes.length; i++) {
          var source = quotes[i].getAttribute("source");
          if (!source) continue;
          var para = document.createElement("span");
          var link = document.createElement("a");
          para.className = "attribution";
          para.appendChild(document.createTextNode(" "));
          link.setAttribute("href",source);
          link.appendChild(document.createTextNode("(source)"));
       quotes[i].parentNode.insertBefore(link,quotes[i].nextSibling);
       quotes[i].parentNode.insertBefore(para,quotes[i].nextSibling);
     }

 }
This is a (probably not clean) hack and rewrite of some code from 24 ways

Still to do:
  • Don't display "Show Sources" link if there is nothing to reveal.
  • Don't let the user click it over and over
  • improve formatting of the page ( applys to the whole website)



Replys: