Примерно так (допилите сами)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Untitled Document</title>
<script type="text/javascript">
function showPageSource() {
var req = new XMLHttpRequest();
req.open("GET", location.href, false);
req.send(null);
if (req.status == 200) {
var wnd = window.open("about:blank", "Page source", "");
var doc = wnd.document;
doc.open();
doc.write("<html><head><title>Page source</title></head><body><xmp>");
doc.write(req.responseText);
doc.write("</x" + "mp></b" + "ody></h" + "tml>");
doc.close();
}
}
</script>
</head>
<body>
<p><a href="#" onclick="showPageSource();">Исходный код страницы</a></p>
</body>
</html>
P.S. Запускать на сервере.