当前位置: 首页 > 图文教程 > 网络编程 > ASP > 给blog加上运行代码功能

ASP
认识和优化connection对象
优化你的ASP程序
ASP实现简单的网页保护
在ASP中限制同一表单被多次提交
Request 对象 属性和方法
asp的Request对象
全角与半角字符的相互转换的asp函数
asp session 使用数组
防止ASP Session丢失的方法
cookies和session的关系
无组件不能上传rar,zip其它非图片文件
网站设计时应注意的SEO细节
asp代码--fso创建文件夹
ASP转化ip地址为长整型数字
关于script的dictionary对象的用法
asp过滤不文明字符的函数
fso删除当前文件夹下所有的内容
asp中将字符转换成变量使用
asp数组随机排序
解决asp被杀毒软件误删的方法

ASP 中的 给blog加上运行代码功能


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 53 ::
收藏到网摘: n/a

在和尚那里看到他给z-blog加上了运行代码功能,放了几天假,有些怕怕再这样闲下去会生锈的,在补了一个半小时的觉之后,也给blog加上运行功能,因为是从L-Blog修改而来,因此同样适用于L-Blog,另外,FBS也是L-Blog修改而来,应该也可以使用本文中的方法来添加运行代码功能。另外,由于复制代码和保存代码还没有找到兼容各浏览器的解决方法,就没有加进来了。
示例:
步骤如下:
1. 在 include/common.js 中添加如下代码:
复制代码 代码如下:

function runCode(codeobjid) {
var codeobj=document.getElementById(codeobjid)
var codestr=codeobj.value;
if (codestr!="") {
var codewin=window.open('','','');
codewin.document.open('text/html','replace');
codewin.opener = null
codewin.document.write(codestr);
codewin.document.close();
}

}
2. 在 include/ubbcode.asp 中找到 strContent=re.Replace(strContent,"【code】")(把【】换成[]),在此之后添加如下代码:
L-Blog:
复制代码 代码如下:

re.Pattern="\[html\](<br>)+"
strContent=re.Replace(strContent,"【html】")

FBS:
复制代码 代码如下:

re.Pattern="\[html\](<br />)+"
strContent=re.Replace(strContent,"【html】")

再找到 re.Pattern="\[code\](.*?)\[\/code\]",然后在段代码的 Set strMatches=Nothing 之后添加如下代码:
复制代码 代码如下:

re.Pattern="\[html\](.*?)\[\/html\]"
Set strMatches=re.Execute(strContent)
For Each strMatch In strMatches
RNDStr=Int(7999 * Rnd + 2000)
tmpStr1=strMatch.SubMatches(0)
strContent= Replace(strContent,strMatch.Value,"<textarea rows=""10"" "_
&"style=""width:90%;"" class=""input_border"" id=""HTML_"&RNDStr&""">"_
&tmpStr1&"</textarea><br />"_
&"<input type=""button"" onclick=""runCode('HTML_"&RNDStr&"');"" value=""运行代码"" />"_
&" [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]")
Next

Set strMatches=Nothing
3. 修改完成,在发表日志时就可以使用【html】要运行的代码【/html】(将【】替换成[])来使用运行代码功能。