加入如下代码:(注意浏览器的安全级别不能太高)<OBJECT id="WebBrowser" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" 
VIEWASTEXT> 
</OBJECT> <input onclick="document.all.WebBrowser.ExecWB(6,1)" type="button" value="打印"> <input onclick="document.all.WebBrowser.ExecWB(6,6)" type="button" value="直接打印"> 
<input onclick="document.all.WebBrowser.ExecWB(8,1)" type="button" value="页面设置"> 
<input onclick="document.all.WebBrowser.ExecWB(7,1)" type="button" value="打印预览">&nbsp;<INPUT type="button" value="关闭窗口" onclick="javascript:window.close()"> 

解决方案 »

  1.   

    不好意思 我是指在 hta 里 
      

  2.   

    详细说一下
    某个hta(不是html )中有以下代码,我想打印部份内容,这样打印提示有错误<script>
    function pHta(){
    var thisStr=document.getElementById("dStr").innerHTML;
    var oWin=window.open("","");
    oWin.write(thisStr);
    oWin.print();
    }
    </script>
    <input type="button" value="打印" onclick="pHta()">
    <div id="dStr">打印内容</div>如何实现
      

  3.   

    才学JS,抛个砖,一种方法是用execCommand来实现:<HTML><BODY>
    <Button onClick="DoThings()">确定</Button>
    <Script>
    function DoThings(){
        var oWin = window.open("");
        oWin.document.write("<HTML><BODY>Hello,World!</BODY></HTML>");
        oWin.document.execCommand("Print");
        oWin.close();
    }
    </Script>
    </BODY></HTML>另外由于是在HTA中,可以调用wscript.shell对象来发送CTRL+P。
    不过上面的两种方法都会弹出打印机的对话框。
    另外还可以用Scripting.FileSystemObject对象打开prn对象来打印纯文本:var fso = new ActiveXObject("Scripting.FileSystemObject");
    var prn = fso.OpenTextFile("prn",2,true);
    prn.Write(String.fromCharCode(27,64));
    prn.Write(String.fromCharCode(27,67,40));
    prn.Write(String.fromCharCode(27,69));
    prn.WriteLine("Hello,World!");