Posted By

gbot on 04/16/08


Tagged

window open mootools


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

gbot
ianmonge


Mootools set file types to open in new window


 / Published in: JavaScript
 

URL: http://davidwalsh.name/dw-content/open-links.php

From: David Walsh. http://davidwalsh.name/dw-content/open-links.php

  1. /* classes */
  2. var OpenLinks = new Class({
  3. //initialization
  4. initialize: function(file_extensions,override_targets,target,no_class) {
  5.  
  6. //analyze all anchors
  7. $$('a').each(function(el) {
  8.  
  9. //check each href for case-insensitive file extensions
  10. var str = el.get('href');
  11. var ext = str.substring(str.lastIndexOf('.') + 1,str.length)
  12. if(file_extensions.contains(ext.toLowerCase()) && ((override_targets || !el.get('target')) && !el.hasClass(no_class + '')))
  13. {
  14. el.setProperty('target',target ? target : '_blank');
  15. el.setStyle('color','#f00');
  16. }
  17. });
  18. }
  19. });
  20.  
  21. /* do it! */
  22. window.addEvent('domready', function() {
  23. //enter in as lower case
  24. var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png'],1,'_blank','no-target');/works
  25. //var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png'],1,'_blank');//works
  26. //var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png'],1);//works
  27. //var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png'],0);//works
  28. //var olinks = new OpenLinks(['doc','pdf','xls','jpg','gif','png']);//works
  29. });

Report this snippet  

You need to login to post a comment.