把一字符串通过javascript当作html代码运行为一个页面

把一字符串通过javascript当作html代码运行为一个页面。这里的字符串,可以通过javascript获取密文,并解密然后运行成为页面。可以通过这种方式完成简单的防监控作用。2010-10-10 21:45

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>runcode</title>
</head>

<body>
<script language="JavaScript" type="text/JavaScript">
//运行文本域代码
function runEx(cod1) {
 cod=document.all(cod1)
 var code=cod.value;
 if (code!=""){
 var newwin=window.open('','',''); //打开一个窗口并赋给变量newwin。
 newwin.opener = null // 防止代码对论谈页面修改
 newwin.document.write(code); //向这个打开的窗口中写入代码code,这样就实现了运行代码功能。
 newwin.document.close();
}
}
</script>
<textarea name="textarea" cols="60" rows="10" id="rn01"><font color="red">加入HTML代码</font></textarea>
<br><INPUT onclick="runEx('rn01')" type="button" value="运行代码" style="cursor:hand">&nbsp;&nbsp;[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
</body>
</html>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据