Posted By

DaveChild on 05/11/09


Tagged

javascript source


Versions (?)

JavaScript View Page Source


 / Published in: JavaScript
 

URL: http://www.addedbytes.com

  1. function viewSource() {
  2. var httpRequest;
  3. try {
  4. httpRequest = new XMLHttpRequest();
  5. }catch(trymicrosoft) {
  6. try {
  7. httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  8. } catch(oldermicrosoft) {
  9. try {
  10. httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  11. } catch(failed) {
  12. httpRequest = false;
  13. }
  14. }
  15. }
  16. if(!httpRequest) {
  17. return false;
  18. }
  19.  
  20. httpRequest.onreadystatechange = function() {
  21. if(httpRequest.readyState == 4) {
  22. if(httpRequest.status == 200) {
  23. document.body.innerHTML = '<pre id="pageSource"></pre>';
  24. document.getElementById('pageSource').innerText = httpRequest.responseText;
  25. }
  26. }
  27. }
  28. httpRequest.open('GET',document.location.href,true);
  29. httpRequest.send(null);
  30. }

Report this snippet  

You need to login to post a comment.