使用Prototype将Rel External更改为Target Blank

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Prototype将Rel External更改为Target Blank相关的知识,希望对你有一定的参考价值。

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>

以上是关于使用Prototype将Rel External更改为Target Blank的主要内容,如果未能解决你的问题,请参考以下文章