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;
文章来源:http://www.ifcode.net/?p=64
通过javascript扩展链接
本文介绍了一种使用JavaScript实现外部链接在新窗口中打开的方法。通过遍历页面中的所有锚点元素并检查其属性,该脚本能够识别出带有特定属性的外部链接,并设置目标属性为'_blank',确保链接在新窗口中打开。

被折叠的 条评论
为什么被折叠?



