博客园的代码运行
网页中嵌入可以点击“运行代码”执行html/css/js代码
html代码
<textarea name="textarea" cols="60" rows="10" id="rn01">运行的代码</textarea> <br> <input onclick="runWin('rn01')" type="button" value="运行代码" style="cursor:hand"> 点击“运行代码”
JS代码
//运行文本域代码
function runWin(code) {
cod=document.all(code)
var code=cod.value;
if (code!=""){
var newwin=window.open('','',''); //打开一个窗口并赋给变量newwin。
newwin.opener = null // 防止代码对页面修改
newwin.document.write(code); //向这个打开的窗口中写入代码code,这样就实现了运行代码功能。
newwin.document.close();
}
}
效果展示:

浙公网安备 33010602011771号