javascript脚本运行窗口 复制 保存

<script type="text/JavaScript"> alimama_pid="mm_11307516_1146824_2589042"; alimama_titlecolor="0000FF"; alimama_descolor ="000000"; alimama_bgcolor="FFFFFF"; alimama_bordercolor="E6E6E6"; alimama_linkcolor="008000"; alimama_bottomcolor="FFFFFF"; alimama_anglesize="0"; alimama_bgpic="0"; alimama_icon="0"; alimama_sizecode="12"; alimama_width=468; alimama_height=60; alimama_type=2; </script> <script src="http://a.alimama.cn/inf.js" type="text/javascript"> </script>



     解决了在firefox下直接复制的问题,但执行代码中包含引用js文件的标签,在firefox中则脚本无法下载,不能正确执行。有高手可以切磋下!
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  4. <title>运行复制保存</title>
  5. </head>

  6. <body>
  7. <script language="JavaScript" type="text/JavaScript">
  8. //运行文本域代码
  9. function runCode(id) {
  10.         cod=document.getElementById(id);
  11.         var codcode=cod.value;
  12.         if (code!=""){
  13.             var newwin=window.open('','',''); //打开一个窗口并赋给变量newwin。
  14.             newwin.document.open('text/html','replace');
  15.             newwin.opener = null // 防止代码对论谈页面修改
  16.             newwin.document.write(code); //向这个打开的窗口中写入代码code,这样就实现了运行代码功能。
  17.             newwin.document.close();
  18.         }
  19. }
  20. function copyCode(id)
  21. {
  22.      var text2copy = document.getElementById(id).value;
  23.      if (window.clipboardData)
  24.      {
  25.      window.clipboardData.setData("Text",text2copy);
  26.      }
  27.      else
  28.      {
  29.      var flashcopier = 'flashcopier';
  30.      if(!document.getElementById(flashcopier))
  31.      {
  32.      var divholder = document.createElement('div');
  33.      divholder.id = flashcopier;
  34.      document.body.appendChild(divholder);
  35.      }
  36.      document.getElementById(flashcopier).innerHTML = '';
  37.      var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//这里是关键
  38.      document.getElementById(flashcopier).innerHTML = divinfo;
  39.      }
  40.      return true;
  41. }

  42. function saveCode(id) {
  43.       var tcode=document.getElementById(id).value;
  44.     var winname = window.open('', '_blank', 'top=10000');
  45.     winname.document.open('text/html', 'replace');
  46.     winname.document.writeln(tcode);
  47.     winname.document.execCommand('saveas','','code.html');
  48.     winname.close();
  49. }

  50. function createMap(){
  51.         var map2 = new LTMaps("map2");
  52.         map2.centerAndZoom(new LTPoint(11640969,3994940),6);
  53.         var points = new Array();
  54.         points.push( new LTPoint( 11629376 , 3995776 ) );
  55.         points.push( new LTPoint( 11642688 , 3988608 ) );
  56.         points.push( new LTPoint( 11641152 , 3992640 ) );         
  57.         var polyLine = new LTPolyLine(points);
  58.         map2.addOverLay(polyLine);  
  59. }
  60. </script>
  61. <textarea name="textarea" cols="60" rows="10" id="rn01">
  62.         <html xmlns:v="urn:schemas-microsoft-com:vml">
  63.         <head>
  64.         <meta http-equiv="content-type" content="text/html; charset=GB2312"/>
  65.         <meta name="keywords" content=""/>
  66.         <title>地图</title>
  67.         <style type="text/css">v/:*{behavior:url(#default#VML);}</style>
  68.         <script type="text/javascript" src="http://api.51ditu.com/js/maps.js"></script>
  69.         <script type="text/javascript">
  70.              function createMap(){
  71.                     var map2 = new LTMaps("map2");
  72.                     map2.centerAndZoom(new LTPoint(11640969,3994940),6);
  73.                     var points = new Array();
  74.                     points.push( new LTPoint( 11629376 , 3995776 ) );
  75.                     points.push( new LTPoint( 11642688 , 3988608 ) );
  76.                     points.push( new LTPoint( 11641152 , 3992640 ) );         
  77.                     var polyLine = new LTPolyLine(points);
  78.                     map2.addOverLay(polyLine);  
  79.             }
  80.         </script>
  81.         </head>
  82.         <body onload="createMap()">
  83.         <div id="map2" style="width:400px; height:300px;"></div>
  84.         
  85.         </body>
  86.         </html>

  87. </textarea>
  88. <br><input onclick="runCode('rn01')" type="button" value="运行代码" style="cursor:hand">
  89. <input type=button value="复制" onclick="copyCode('rn01')">
  90. <input type=button value="保存" onclick="saveCode('rn01')">
  91. <br/>
  92. </body>
  93. </html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值