/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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); }
URL: http://www.addedbytes.com