/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Validate target attribute XHTML Strict or HTML 4.0 Strict http://www.flash-free.org/en/2008/05/17/validar-atributo-target-xhtml-strict-o-html-40-strict/ */ // ==================================== with MooTools function fix_external_links() { $ES('a').each(function(el) { if (el.getProperty('rel') == 'external') { el.addEvent('click', function(e) { e = new Event(e); e.stop(); window.open(this.getProperty('href')); }.bind(el)); } }); } window.addEvent('domready', function() { fix_external_links(); }); // ==================================== without MooTools function fix_external_links() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i = 0; i < anchors.length; i++) { var anchor = anchors[i]; if (anchor.getAttribute("rel") && anchor.getAttribute("rel") == "external") { anchor.target = "_blank"; } } } window.onload = fix_external_links;
URL: http://www.flash-free.org/en/2008/05/17/validar-atributo-target-xhtml-strict-o-html-40-strict