您现在的位置是:首页 > 电脑技术查询 > web开发

【编程游戏】网页版脚本输出自己。该如何处理

编辑:chaxungu时间:2022-10-02 23:24:04分类:web开发

【编程游戏】网页版脚本输出自己。
比如:C/C++ codemain(){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分

下周一结贴给分。

模板:HTML code<script>/* todo */</script>

谢谢关注。

------解决方案--------------------
JScript code<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,"&lt;$1&gt;"); document.body.innerHTML=str; } );};</script>
------解决方案--------------------
zswang

你的代码运行不通过,哇哈哈!
没有考虑页面加载的问题
------解决方案--------------------
我来一个
JScript codefunction encode(v){return v.replace(/</g,'&lt;');}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);}
------解决方案--------------------
HTML code<script type="text/javascript"> window.onload=function() { var arrcontrol=document.getElementsByTagName("script")[0]; document.write(arrcontrol.parentNode.innerHTML.replace(/</g,"&lt;").replace(/>/g,"&gt;")) };</script>
------解决方案--------------------
探讨

我来一个
JScript code
function encode(v){return v.replace(/</g,'&amp;lt;');}
window.onload=function(){
var pre=document.createElement('pre');
pre.innerHTML=typeof(HTMLElement) != "undefined"?
……

------解决方案--------------------
借楼上的构思。JScript code<script language="javascript">var a=[];a[0]='script',a[1]='&lt;',a[2]='&gt;';document.write(document.getElementsByTagName('script')[0].parentNode.innerHTML.replace(/(script|SCRIPT)/g,a[0]).replace(/&/g,'&amp;').replace(/</g,a[1]).replace(/>/g,a[2]));</script>
------解决方案--------------------