Created
July 24, 2009 11:24
-
-
Save DaveChild/154010 to your computer and use it in GitHub Desktop.
JavaScript function that will fetch the source of the page being viewed. Based, I think, on http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11340
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function viewSource() { | |
var httpRequest; | |
try { | |
httpRequest = new XMLHttpRequest(); | |
}catch(trymicrosoft) { | |
try { | |
httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); | |
} catch(oldermicrosoft) { | |
try { | |
httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); | |
} catch(failed) { | |
httpRequest = false; | |
} | |
} | |
} | |
if(!httpRequest) { | |
return false; | |
} | |
httpRequest.onreadystatechange = function() { | |
if(httpRequest.readyState == 4) { | |
if(httpRequest.status == 200) { | |
document.body.innerHTML = '<pre id="pageSource"></pre>'; | |
document.getElementById('pageSource').innerText = httpRequest.responseText; | |
} | |
} | |
} | |
httpRequest.open('GET',document.location.href,true); | |
httpRequest.send(null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment