/ Published in: JavaScript
The html attribute 'target="_blank"' for links is no longer valid code as of XHTML Strict 1.0. This code will run using mootools on domready to send all clicks to new windows when going to an external domain.
Expand |
Embed | Plain Text
window.addEvent('domready', function() { // modified from http://joesong.com/2009/11/external-links-in-new-window-passive-and-with-mootools/ // to avoid using the 'target' attribute, which is not part of xhtml 1.0 strict 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)) { window.open(target.get('href'), '_blank'); return false; } }); });
You need to login to post a comment.
