清理由Word导出的HTML文档的JS脚本

当把一个Word文档导出成HTML格式时,会发现到处的文件之中会有很多样式,结果使得文件很大。下面的这个脚本可以清理其中的样式信息,只保留数据信息。

使用方法:

把<script src="ParseHtml.js" language="javascript"></script>放到html文件的<head>中,然后打开文件,会看到在页面的最下面多出了一个按钮。点击,弹出一个新的页面,并提示保存文件。保存即可。

说明:因为时间比较仓卒,所以可能会有一些错误,请大家帮忙指正。

//<script src="ParseHtml.js" language="javascript"></script> function Parse(root) {  var html="";  var tag;  var value;  for(var i=0;i<root.childNodes.length;i++)    {      if(root.childNodes[i].id=="QLSC_MUMU_ButtonParse")    continue;       tag=root.childNodes[i].tagName;   value=root.childNodes[i].nodeValue;   if((tag+"").toLowerCase()=="font")    html+=Parse(root.childNodes[i]);   if(tag+""=="undefined")    html+=value;   else   {    if(root.childNodes[i].childNodes.length>0)    {     html+="<"+tag+">";     if(value!=null)      html+=value;     html+=Parse(root.childNodes[i]);     html+="</"+tag+">";    }    else    {     html+="<"+tag+">";     if(value!=null)     {      if(value!=null)      {       html+=value;       html+="</"+tag+">";      }        }     else     {      tmp=(tag+"").toLowerCase();      if(tmp=="script"||tmp=="title"||tmp=="link"||tmp=="meta"||tmp=="style")          html+="</"+tag+">";     }    }   }  }  return html; }

function Start() {  var ret=Parse(document.documentElement);  var wnd=window.open("","mumu","addressbar=no,toolbar=yes,scrollbars=yes,resizable=yes",true);   wnd.document.write("<html>"+ret+"</html>");   wnd.document.close();   wnd.document.execCommand('SaveAs'); } function Init() {  var body=document.getElementsByTagName("body").item(0);  var node=document.createElement("input");

 node.setAttribute("value","Parse");  node.setAttribute("type","button");  node.setAttribute("id","QLSC_MUMU_ButtonParse");   body.appendChild(node);  document.getElementById("QLSC_MUMU_ButtonParse").οnclick=Start; } window.οnlοad=Init;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值