Posted By

fruehjahr on 01/01/09


Tagged

html strict prototype links


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

fruehjahr
Jamie


Change Rel External to Target Blank using Prototype


 / Published in: JavaScript
 

URL: http://blog.ninedays.org/2008/04/07/change-rel-external-to-target-blank-using-prototype/

There's been a popular trend to use JavaScript to add target="_blank" to anchors with rel="external". So in the name of making everything in my site Prototype based I worked out a script to do just that.

  1. <script type="text/javascript">
  2. Event.observe(window, 'load', function() {
  3. $$('a[rel="external"]').each(function(link){
  4. if(link.readAttribute('href') != '' && link.readAttribute('href') != '#'){
  5. link.writeAttribute('target','_blank');
  6. }
  7. });
  8. });
  9. </script>

Report this snippet  

You need to login to post a comment.