Validate Local Page Markup in JavaScript


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



Copy this code and paste it in your HTML
  1. var validateLocalMarkup = function() {
  2. (function() {
  3. var xhr = new XMLHttpRequest();
  4. xhr.open('GET', window.location, true);
  5. xhr.send(null);
  6.  
  7. xhr.onreadystatechange = function() {
  8. if (xhr.readyState !== 4) return;
  9. if (!xhr.status || xhr.status === 200) {
  10. var source = xhr.responseText;
  11. var f = document.createElement('form'), i = document.createElement('input');
  12.  
  13. f.action = 'http://validator.w3.org/check';
  14. f.enctype = 'multipart/form-data';
  15. f.method = 'post';
  16. f.target = '_blank';
  17.  
  18. i.type = 'hidden';
  19. i.name = 'fragment';
  20. i.value = source;
  21.  
  22. f.appendChild(i);
  23. document.body.appendChild(f);
  24. f.submit();
  25. document.body.removeChild(f);
  26. }
  27. };
  28. })();
  29. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.