| |||
| There is an unobstrusive way of doing it, use JavaScript. Create a file called externallinks.js and add this code: All it does is find every element in the page with the 'a' attribute and if it has the rel="external" attribute, it will add the target="_blank" behaviour. Code: addLoadEvent(externalLinks);
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";
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
} <script src="externallinks.js" type="text/javascript"></script> Each link you want to popup a window just add the rel="external" to it. Techically, it still won't make your page valid, because you're adding the attribute, target="_blank", through JavaScript. However, validators won't pick this up and many people use a method similar to this. So your page will be valid as such. |
![]() |
| Thread Tools | |
| Display Modes | |
| |