posts - 59, comments - 244, trackbacks - 0, articles - 0
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          html編輯器(自己記錄用)

          Posted on 2011-03-12 22:39 penngo 閱讀(508) 評(píng)論(0)  編輯  收藏 所屬分類: javascript

          這幾天有點(diǎn)蛋疼,有個(gè)新系統(tǒng)的HTML編輯器居然在IE6下部分功能不能用,想讓客戶升級(jí)下IE版本,結(jié)果客戶的機(jī)子有些舊系統(tǒng)只能在IE6下運(yùn)行,不能升級(jí)。只好用最笨的方法把部分代碼抽出來(lái)在IE6下調(diào)試。本文是把自己寫的一小部分調(diào)試代碼記錄下,下次找起來(lái)時(shí)方便點(diǎn)。
          exec.htm

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
              
          <title>無(wú)標(biāo)題頁(yè)</title>
          </head>
          <body>
          <script language="javascript">
          var brower = function(){
              
          var a = navigator.userAgent.toLowerCase();
              
          if(a.indexOf("msie"> -1){
                  
          var re = new RegExp("msie\\s?([\\d\\.]+)""ig");
                  
          var arr = re.exec(a);
                  
          if(parseInt(RegExp.$1>=5.5){
                      
          return "IE";
                  }

              }

              
          else if(a.indexOf("firefox"> -1){
                  
          return "FF";
              }

          }
          ();

          function execCom(cmd){
              document.execCommand(cmd, 
          """");
          }

          function code(){
              
          var fram = document.getElementById("editFrame").contentWindow;
              
          var bo = fram.document.body.innerHTML;
              document.getElementById(
          "myarea").value = bo;
          }

          function inserCode(){
              
          var value = document.getElementById("myarea").value;
              
          var fram = document.getElementById("editFrame").contentWindow;
              fram.document.body.innerHTML 
          = value;
          }

          </script>



          <table>
              
          <tr>
                  
          <td colspan="2">
                      
          <input type="button" onclick="execCom('UNDO')" value="撤消" />
                      
          <input type="button" onclick="execCom('REDO')" value="重復(fù)" />
                      
          <input type="button" onclick="code()" value="查看源碼" />
                      
          <input type="button" onclick="inserCode()" value="插入源碼" />
                  
          </td>
              
          </tr>
              
          <tr>
                  
          <td>
                      
          <textarea id="myarea" style="background-color:#99b6d5;width:200px; height:400px;" cols="10" >  
                      
          </textarea>
                  
          </td>
                  
          <td>
                      
          <iframe id="editFrame" src="my.htm" width="300px" height="400px" />
                  
          </td>
              
          </tr>
              
          <tr>
                  
          <td>
                      
                  
          </td>
              
          </tr>
          </table>
          </body>
          </html>

          my.htm
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
              
          <title>無(wú)標(biāo)題頁(yè)</title>
          </head>
          <body contentEditable="true" style="background-color:#99b6d5;">
          <input type="button" value="確認(rèn)" />
          <input type="text" />
          <input type="button" value="復(fù)選框" />
          </body>
          </html>

          效果圖:
          主站蜘蛛池模板: 车致| 皋兰县| 道孚县| 建平县| 东宁县| 益阳市| 西和县| 汶上县| 青浦区| 常宁市| 灵川县| 西青区| 清丰县| 铁岭市| 响水县| 芒康县| 洪湖市| 定陶县| 诏安县| 财经| 出国| 府谷县| 彰化县| 同心县| 广宁县| 平和县| 永定县| 绥滨县| 读书| 鄯善县| 漳浦县| 剑河县| 威远县| 讷河市| 巨鹿县| 苏尼特左旗| 桑植县| 眉山市| 聂拉木县| 平泉县| 咸丰县|