zoukankan      html  css  js  c++  java
  • JS Runcode运行网页上的HTML/CSS/Javascrip代码




    <!DOCTYPE html> <html> <head> <meta charset="gb2312" /> <title>runcode-运行HTML/CSS/Jvascrip代码</title> </head> <body> <form> <textarea name="codearea" style="800px; height:600px"> </textarea> <br /> <input name="run" type="button" value="运行代码"> </form> <script> (function(){ function run(code){ var newWin = window.open("", "_blank", ""); newWin.opener = null; // 防止代码对页面修改 newWin.document.open(); newWin.document.write(code); newWin.document.close(); } //遍历页面中运行代码按钮 var executes = document.getElementsByName("run"); for(var i=0; i<executes.length; i++){ executes[i].onclick = function(){ var code = this.form.codearea.value; run(code); }; } }()); </script> </body> </html>

    要在博客中插入可运行的代码:

    一 将博客园后台的文本编辑器切换到的HTML视图下插入代码:

    <form>
        <textarea name="codearea" style="800px; height:600px">
        
        </textarea>
        
        <br />
        <input name="run" type="button" value="运行代码">
    </form>
    

    表单元素的样式可以根据需要调整。

    二 、在textarea中插入需要运行的代码,代码需要经过HTML ENCODE 否则提交的时候会被处理。

    三、在页面底部加入代码:

    <script type="text/javascript" src="http://www.buyed.cn/blog/script/runcode.js"></script>

    或者拷贝runcode.js中的代码到页面上。

    演示:

  • 相关阅读:
    漫画 | 一台Linux服务器最多能支撑多少个TCP连接?
    frida hook pthread_create
    mac搜索so中的字符串
    字节字符串和数字互转
    twsited使用延迟项,并发量限制
    常见汇编指令和EFLAGS寄存器对应位的含义
    scrapy设置cookie的三种方式
    G1GC 读书笔记
    SLF4J 适配图
    支付宝和微信提现有办法免费了!
  • 原文地址:https://www.cnblogs.com/rentj1/p/2716532.html
Copyright © 2011-2022 走看看