tips and tricks for movable type
open external, non-js links in new window
March 30, 2002
In this Community Forum topic, shiva7663 offers what looks like the best solution.
function outLinks(){
var d = document.links; var j = "javascript:"; var b = "_blank";
for (var i = 0; i < (d.length); i++)
if (d[i].protocol != j && d[i].hostname != document.domain)
d[i].target = b;
}
window.onload = function() { outLinks(); }
var d = document.links; var j = "javascript:"; var b = "_blank";
for (var i = 0; i < (d.length); i++)
if (d[i].protocol != j && d[i].hostname != document.domain)
d[i].target = b;
}
window.onload = function() { outLinks(); }
TrackBack: 1
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/17)
» links script
Excerpt: i wanted to make it so that external links open in a new window. only script i found was one
Weblog: Written on the Sky
Tracked: 01.30.03 11:24 AM
Comments
Wow, I feel like a midshipman who has just been Mentioned in Dispatches....
A lot of people over the years have tilted at that particular windmill, especially since the use of target=_blank had been deprecated by the HTML 4.01 Strict DTD when frames were separated out with their own DTD (even though this is a non-frames use of the feature). The topic is still good for generating flamewars when mentioned in various online venues.
Great scripts - and just what I've been looking for.
However, sometimes my site will load without the www in front of the domain, in which case the script seems unable to recognize the url - causing it to open all links in a new window (the internal ones as well). Is there a way to modify the script to correct this problem?
Tanks in advance,
Janus