Validate target attribute XHTML Strict or HTML 4.0 Strict


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.   Validate target attribute XHTML Strict or HTML 4.0 Strict
  3.   http://www.flash-free.org/en/2008/05/17/validar-atributo-target-xhtml-strict-o-html-40-strict/
  4.  
  5. */
  6.  
  7. // ==================================== with MooTools
  8.  
  9. function fix_external_links() {
  10. $ES('a').each(function(el) {
  11. if (el.getProperty('rel') == 'external') {
  12. el.addEvent('click', function(e) {
  13. e = new Event(e);
  14. e.stop();
  15. window.open(this.getProperty('href'));
  16. }.bind(el));
  17. }
  18. });
  19. }
  20.  
  21. window.addEvent('domready', function() {
  22. fix_external_links();
  23. });
  24.  
  25. // ==================================== without MooTools
  26.  
  27. function fix_external_links() {
  28. if (!document.getElementsByTagName) return;
  29. var anchors = document.getElementsByTagName("a");
  30. for (var i = 0; i < anchors.length; i++) {
  31. var anchor = anchors[i];
  32. if (anchor.getAttribute("rel") && anchor.getAttribute("rel") == "external") {
  33. anchor.target = "_blank";
  34. }
  35. }
  36. }
  37. window.onload = fix_external_links;

URL: http://www.flash-free.org/en/2008/05/17/validar-atributo-target-xhtml-strict-o-html-40-strict

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.