Advertisement
Guest User

iEFdev

a guest
Jan 7th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // A modified version of http://snipplr.com/view/30551/ by birnamdesigns
  2.  
  3. /**
  4. * Function to open links to external sites in new windows.
  5. * The 'target' attribute, is not part of xhtml 1.* strict.
  6. * A modified version of: http://snipplr.com/view/30551/
  7. * Added a short check for class="ext" to control local links as well.
  8. */
  9. window.addEvent('domready', function() {
  10.     var currentDomain = window.location.host;
  11.     $(document.body).addEvent('click', function(evt) {
  12.         var target = $(evt.target);
  13.         if (target.get('tag') !== 'a') {
  14.             target = target.getParent();
  15.         }
  16.  
  17.         if (target && target.get('tag') === 'a' && target.get('href').test('http') && !target.get('href').test(currentDomain) || target && target.hasClass('ext')) {
  18.             window.open(target.get('href')); return false;
  19.         }
  20.     });
  21. });
  22.  
  23. // Example local link: Add "ext" to the class.
  24. // <a href="http://yoursite.com/" class="foo ext bar">Local link</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement