External links in a new window

The 'target' attribute is deprecated and should not be used. Here is a quick and easy way to replicate that behaviour with javascript. I got the idea - well, I guess I nicked the idea - from Kevin Yank's article on Sitepoint. My script is a little bit shorter and I've cut out the explanation.

HTML
<a rel="external" href="http://tinyurl.com/rdefj">Kevin Yank's article</a>
javascript
function external() {
var as=document.getElementsByTagName('a');
 for (i=0; i<as.length; i++) {
  if (as[i].getAttribute('rel')=='external') {
   as[i].onclick=function() {
    !window.open(this.href);
    return false;
   }
  }
 }
}
window.onload=external;

Comments

#1
2022-08-28 WxevWhits says :

writing an essay outline <a href="https://essaymeshing.com/ ">essay for scholarship</a> atlas shrugged essay contest

#2
2022-08-28 NxerBossy says :

driving essay <a href="https://essaymesa.com/ ">essay about abortion</a> best essay

Comment form

Please type the word 'brown' here:

BB code available :

  • [b]...[/b] : bold
  • [it]...[/it] : italic
  • [q]...[/q] : quote
  • [c]...[/c] : code
  • [url=...]...[/url] : url