hz-gb-2312 转码工具

<html>
<head>
<title>hz-gb-2312 转码工具</title>
<HTA:APPLICATION
    APPLICATIONNAME="CabMKR"
    Icon="http://ialvin.cn/favicon.ico"
    ID="oHTA"
    CAPTION="yes"
    CONTEXTMENU="no"
    INNERBORDER="no"
    BORDER="thin"
    BORDERSTYLE="normal"
    MAXIMIZEBUTTON="no"
    MINIMIZEBUTTON="yes"
    SHOWINTASKBAR="yes"     
    INGLEINSTANCE="no"     
    SYSMENU="yes"
    VERSION="1.0"
    windowstate="normal"
    SCROLL="no"/>

<style type="text/css">
html,body{ font-size:12px; margin:0; overflow:hidden; }
fieldset{ padding:5px; margin:5px; text-align:center; }
</style>

<script type="text/JScript">
window.resizeTo(480, 310);
window.moveTo((screen.width-480)/2, (screen.height-310)/2);
var $ = function(id) { return document.getElementById(id); };
String.prototype.saveTo = function(path, cSet) {
    var out = new ActiveXObject("ADODB.Stream");
    with (out) { Type=2; Open(); CharSet=cSet||"GBK"; Position=0; WriteText=this; SaveToFile(path,2); Close(); }
    delete out;
};
String.loadFrom = function(path, cSet) {
    var ins = new ActiveXObject("ADODB.Stream");
    with (ins) { Type=2; Mode=3; Open(); CharSet=cSet||"GBK"; Position=0; LoadFromFile(path); }
    var s = ins.ReadText();
    ins.Close(); delete ins;
    return s;
};

function converEncoding(str, wcs, rcs) {
    var s = new ActiveXObject("ADODB.Stream");
    with (s) { Mode=3; Type=2; Open(); CharSet=wcs; WriteText=str; Position=0; CharSet=rcs; str=ReadText(-1); Close(); }
    delete s; return str;
}
function encode(s) { return converEncoding(s, "hz-gb-2312", "gbk"); }
function decode(s) { return converEncoding(s, "gbk", "hz-gb-2312"); }

function doDecode() {
    //var code = String.loadFrom($('txt').value);
    $("txt").value = decode($('txt').value);
    // code.saveTo("ok.txt");
    // alert("转换编码后的内容已保存到 ok.txt");
}
</script>
</head>
<body>
<fieldset>
    <legend>内容</legend>
    <textarea id="txt" style="width:100%" rows="14"><meta content="~{11>)E`@hV0R5Q'T:UPIzW(R5~}" name="description"></textarea>
    <input type="button" onclick="JScript:doDecode();" value=" 转 码 " />
</fieldset>
</body>
</html>


把上面代码保存成 xxxxx.hta 后,运行.可以用来转码.
posted @ 2009-12-14 20:57  傲衣华少  阅读(346)  评论(0编辑  收藏  举报