在和尚那裡看到他給z-blog加上了運行代碼功能,放了幾天假,有些怕怕再這樣閒下去會生鏽的,在補了一個半小時的覺之後,也給blog加上運行功能,因為是從L-Blog修改而來,因此同樣適用於L-Blog,另外,FBS也是L-Blog修改而來,應該也可以使用本文中的方法來添加運行代碼功能。另外,由於復制代碼和保存代碼還沒有找到兼容各瀏覽器的解決方法,就沒有加進來了。
示例:
步驟如下:
1.在include/common.js中添加如下代碼:
複製代碼代碼如下:
functionrunCode(codeobjid){
varcodeobj=document.getElementById(codeobjid)
varcodestr=codeobj.value;
if(codestr!=""){
varcodewin=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/]",然後在段代碼的SetstrMatches=Nothing之後添加如下代碼:
複製代碼代碼如下:
re.Pattern="/[html/](.*?)/[//html/]"
SetstrMatches=re.Execute(strContent)
ForEachstrMatchInstrMatches
RNDStr=Int(7999*Rnd+2000)
tmpStr1=strMatch.SubMatches(0)
strContent=Replace(strContent,strMatch.Value,"<textarearows=""10"""_
&"style=""width:90%;""class=""input_border""id=""HTML_"&RNDStr&""">"_
&tmpStr1&"</textarea><br/>"_
&"<inputtype=""button""onclick=""runCode('HTML_"&RNDStr&"');""value=""運行代碼""/>"_
&"[Ctrl+A全部選擇提示:你可先修改部分代碼,再按運行]")
Next
SetstrMatches=Nothing
3.修改完成,在發表日誌時就可以使用【html】要運行的代碼【/html】(將【】替換成[])來使用運行代碼功能。