zoukankan      html  css  js  c++  java
  • 博客园 中 运行js


    <p><textarea id="con" style="height: 167px;  375px; margin: 2px;">&lt;script type="text/javascript"&gt;
    alert("alert弹出?");
    &lt;/script&gt;</textarea></p>
    <p><input id="btn" onclick="btn();" type="button" value="运行代码" /></p>
    <p>&nbsp;</p>
    <p><textarea id="theCode" style=" 450px; height: 300px;" title="双击运行代码" ondblclick="runCode('theCode');">这里放入运行的Html代码。
    
    </textarea><br />
    
    <input onclick="runCode('theCode')" type="button" value="运行代码" /> 
    
    <input onclick="doCopy('theCode')" type="button" value="复制代码" /> 
    
    <input onclick="doSave('theCode','test')" type="button" value="保存代码" /></p>
    <script type="text/javascript">// <![CDATA[
    //执行代码
     
     var btn = document.getElementById("btn");
        var con = document.getElementById("con");
        if(btn && con){
            btn.onclick = function(){
                var newwin = window.open('', "_blank", '');
                newwin.document.open('text/html', 'replace');
                newwin.opener = null;
                newwin.document.write(con.value);
                newwin.document.close();
            }
        }
        function runCode(obj) {
     
            var winname = window.open('', "_blank", '');
     
            var content = document.getElementById(obj).value;
     
            winname.document.open('text/html', 'replace');
     
            winname.opener = null
     
            winname.document.writeln(content);
     
            winname.document.close();
     
        }
     
      
     
        //复制代码
     
        function doCopy(obj){
     
            var codeObj = document.getElementById(obj);
     
            clipboardData.setData('text', codeObj.innerText);
     
            alert('已经复制代码');
     
        }
     
      
     
        // 另存为文件
     
        function doSave(obj, filename){  
     
            var win = window.open('', '_blank', 'top=10000');
     
            var code = document.getElementById(obj).innerText;
     
            win.opener = null;
     
            win.document.write(code);
     
            win.document.execCommand('saveas', true, filename);
     
            win.close();
     
        }
    // ]]></script>
  • 相关阅读:
    用Telnet发送HTTP请求
    chrome失去响应问题
    windows应用技巧
    转载:Linux 的系统服务及其配置(略有修改)
    poj2249 排列组合
    poj1068 模拟
    并查集———吉林省赛(六)G题
    著名医生的药方(深搜)
    源代码(C#)
    (课程设计)简单总结
  • 原文地址:https://www.cnblogs.com/laopo/p/6240687.html
Copyright © 2011-2022 走看看