Monday, March 8, 2004

Bounce it Out

  Wrote a little javascript today so that the links on comment authors open in new windows. It just replaces 'a href' with 'a target="_blank" href'. Simple but effective.
  See, Movable Type generates the links in some place that I don't have access to. That's why I have to make the modifications at run time.

I set a Div tag with the ID "Linkville" around the comments section in the template and called the following function from onLoad in the body tag:

function ExternalizeLinks(){
    var texttowrite = document.all.Linkville.innerHTML
    var regExp = /a\shref/gi
    var strExternal = "a target=" + String.fromCharCode(34) + "_blank" + String.fromCharCode(34) + " href"
    texttowrite = texttowrite.replace(regExp,strExternal)
    document.all.Linkville.innerHTML = texttowrite
}

Posted to Tech Tedia + Blog at March 8, 2004 10:03 PM