Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A modified version of http://snipplr.com/view/30551/ by birnamdesigns
- /**
- * Function to open links to external sites in new windows.
- * The 'target' attribute, is not part of xhtml 1.* strict.
- * A modified version of: http://snipplr.com/view/30551/
- * Added a short check for class="ext" to control local links as well.
- */
- window.addEvent('domready', function() {
- var currentDomain = window.location.host;
- $(document.body).addEvent('click', function(evt) {
- var target = $(evt.target);
- if (target.get('tag') !== 'a') {
- target = target.getParent();
- }
- if (target && target.get('tag') === 'a' && target.get('href').test('http') && !target.get('href').test(currentDomain) || target && target.hasClass('ext')) {
- window.open(target.get('href')); return false;
- }
- });
- });
- // Example local link: Add "ext" to the class.
- // <a href="http://yoursite.com/" class="foo ext bar">Local link</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement