Return to Snippet

Revision: 13896
at May 11, 2009 08:46 by DaveChild


Initial Code
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);        
}

Initial URL
http://www.addedbytes.com

Initial Description

                                

Initial Title
JavaScript View Page Source

Initial Tags
javascript

Initial Language
JavaScript