比如:main(){char q=34,n=10,*a="main(){char q=34,n=10,*a=%c%s%c;printf(a,q,a,q,n);}%c";printf(a,q,a,q,n);}程序运行后正好输出自己,一字不差。有一个网站专门收集这类代码-》传送门
历史发起的帖子(C#)传送门要求:
1、htm文件;
2、浏览器中输出源文件一样,包括大小写、标点符号;
3、兼容IE6+、FF、Chrome。奖励:
1、第一个完成,加20分;
2、源文件最短,加100分;
3、之前没有使用过的方法,加10分下周一结贴给分。模板:<script>/* todo */</script>谢谢关注。
历史发起的帖子(C#)传送门要求:
1、htm文件;
2、浏览器中输出源文件一样,包括大小写、标点符号;
3、兼容IE6+、FF、Chrome。奖励:
1、第一个完成,加20分;
2、源文件最短,加100分;
3、之前没有使用过的方法,加10分下周一结贴给分。模板:<script>/* todo */</script>谢谢关注。
<script>
var httpRequest=function(){
var xmlHttp=false;
try{
xmlHttp = new XMLHttpRequest();
}
catch(trymicrosoft){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(othermicrosoft){
try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")}
catch(failed){}
}
}
return xmlHttp;
};
var ajaxGet=function(url,functionCallback){
var xmlHttp = httpRequest();
xmlHttp.open("get",url,true);
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4&&xmlHttp.status == 200){
functionCallback(xmlHttp);
}
};
xmlHttp.send(null);
};
window.onload=function(){
ajaxGet(window.location.href,
function(xmlHttp){
var str=xmlHttp.responseText;
var reg=new RegExp("<([^>]+)>","img");
str=str.replace(reg,"<$1>");
document.body.innerHTML=str;
}
);
};
</script>试试
ajaxGet(window.location.href,
function(xmlHttp){
var str=xmlHttp.responseText;
var reg=new RegExp("<([^>]+)>","img");
str=str.replace(reg,"<$1>");
str=str.replace(new RegExp("\n","img"),"<br/>");
document.body.innerHTML=str;
}
);
};
算是一种方法吧 -- 通过http get。
<script>var q=XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");q.open("GET",location.href,false);q.send();document.write(q.responseText.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"))</script>
没有考虑页面加载的问题
用各种浏览器打开试试吧:http://www.renrousousuo.com/tools/printself.html哥帖代码99%都是经过测试的。
->
var q=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
function encode(v){return v.replace(/</g,'<');}
window.onload=function(){
var pre=document.createElement('pre');
pre.innerHTML=typeof(HTMLElement) != "undefined"?
encode(document.createElement("DIV").appendChild(document.documentElement.cloneNode(true)).parentNode.innerHTML):encode(document.documentElement.outerHTML);
document.body.appendChild(pre);
}
<script type="text/javascript">
window.onload=function()
{
var arrcontrol=document.getElementsByTagName("script")[0];
document.write(arrcontrol.parentNode.innerHTML.replace(/</g,"<").replace(/>/g,">"))
};
</script>
这个没有考虑HTML TAG在ie下大写的问题innerHTML..
16楼实现得比较接近
<script>a=['script','<','>'];d=document;d.write(d.getElementsByTagName('script')[0].parentNode.innerHTML.replace(/script/ig,a[0]).replace(/&/g,'&').replace(/</g,a[1]).replace(/>/g,a[2]));</script>
可以稍作简化
http://www.renrousousuo.com/tools/printself.html
(s = function () { var a = this; (function (b) {document.write('(' + b.s + ')()')})(a); })()
(s = function () { (function (b) {document.write('(' + b.s + ')()')})(window); })()
(s = function(){document.write('(s = ' + window.s + ')()')})()
这么土方法没有人用吧.....
加10分
加10分
oh,yeah!window.onload=function(){
var a = [];
var g = document.documentElement.innerHTML;
a = g.split("<");
var text ="<html>";
for(var i=1;i<a.length;i++){
text+="<"+a[i];
}
document.write(text+"</html>");
}
d = document;str=d.getElementsByTagName('script')[0].parentNode.innerHTML;t = d.createElement("div");
(t.textContent != undefined) ? (t.textContent = str) : (t.innerText = str);
d.write(t.innerHTML);
d = document;str=d.getElementsByTagName('script')[0].parentNode.innerHTML;t = d.createElement("div");
(t.textContent != undefined) ? (t.textContent = str) : (t.innerText = str);
d.write(t.innerHTML);//(s = function(){document.write('(s = ' + window.s + ')()')})()
</script>
<script>document.write("<script>"+document.scripts[0].innerHTML.replace(/&/ig,"&")+"</script>")</script>
<script>
+function(){
var r = /(<script>)([\s\S]*?)(<\/script>)/i;
var s = document.documentElement.innerHTML.match(r)[0];
var ret = s.replace(r,function(a,b,c,d){return b.toLowerCase()+c+d.toLowerCase()});
alert(ret);
}();
</script>
(function(){alert(document.getElementById("my").innerHTML)})();
</script>
//我也来一个吧。^_^
(function(){
var obj = document.getElementsByTagName("script");
document.write(obj[obj.length-1].parentNode.innerHTML.replace(/<([^>]+)>/g, "<$1>").replace(/\n/g,"<br/>").toLowerCase())//你看我输出自己输出自己——
})();
</script>
//我也来一个吧。^_^
(function(){
var obj = document.getElementsByTagName("script");
document.write(obj[obj.length-1].parentNode.innerHTML.replace(/<([^>]+)>/g, function($1,$2){return "<"+$2.toLowerCase()+">"}).replace(/\n/g,"<br/>"))//我输出自己输出自己——
})();
</script>
http://blog.csdn.net/KiteGirl/archive/2010/06/07/5652091.aspx
(s=function () { document.write("(s=" + s + ")()"); })()