Posted By

wesbaker on 07/08/08


Tagged

valid textmate link external XHMTL


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

SpinZ
orion
wizard04


Valid External Links


 / Published in: JavaScript
 

  1. <script type="text/javascript">
  2. function externalLinks() {
  3. if (!document.getElementsByTagName) return;
  4. var anchors = document.getElementsByTagName('a');
  5. for each (anchor in anchors) {
  6. if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
  7. anchor.target = '_blank';
  8. }
  9. }
  10. }
  11.  
  12. window.onload = externalLinks;
  13. </script>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: heinz1959 on July 10, 2008

Again: the "_blank" attribute through the JavaScript backdoor. Better (?) include onclick="window.open(this.href); return false;" inside the a href. This is longer, but XHTML and DOM compliant.

You need to login to post a comment.