<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> 
</object> 
<OBJECT id=closes type=application/x-oleobject 
classid=clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11><param name=Command value=Close></object> 
<SCRIPT> 
function window.onbeforeprint(){ 
alert("打印前事件"); 

function window.onafterprint(){ 
alert("打印后事件"); 
closes.Click(); 

</SCRIPT>
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置> 
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,6) type=button value=打印预览> 
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=页面打印>

解决方案 »

  1.   

    大哥,我想实现打印设置和打印预览iframe中的内容,你给我window.onbeforeprint()和window.onafterprint()干什么??? 不过我还是很感谢你.
      

  2.   

    你改一下不就行了吗,那是我调试的语句,这样写的啦:
    <!-- IE5.5以上 -->
    <OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
    <input type=button value=打印     onclick="document.all.WebBrowser.ExecWB(6,1)">
    <input type=button value=直接打印 onclick="document.all.WebBrowser.ExecWB(6,6)">
    <input type=button value=页面设置 onclick="document.all.WebBrowser.ExecWB(8,1)">
    <input type=button value=打印预览 onclick="document.all.WebBrowser.ExecWB(7,1)">
      

  3.   

    我是想打印一张页面中某一iframe中的内容,不是整张页面.
    哪位大哥帮帮我吧!
      

  4.   

    onclick=document.framename.document.webbrowser.execWB(7,1)
    framename指的是iframe的ID
      

  5.   

    ExecWB后面的参数分别代表什么
      

  6.   

    还是不行,提示document.ifrm1.document为空或不是对象. (ifrm1为iframe的ID)
      

  7.   

    呵呵,果然是和我碰到的问题一样的啊.
    用这个:
    <script>
    document.frames("ifrm").document.execCommand("Print", false);//"ifrm"为iframe的ID
    </script>
      

  8.   

    打印设置的问题上面已经有人帮你解决了,你做一下修改就行了
    <OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
    <input type=button value=页面设置 onclick="document.frames("ifrm").document.WebBrowser.ExecWB(8,1)">
    <input type=button value=打印预览 onclick="document.frames("ifrm").document.WebBrowser.ExecWB(7,1)">
      

  9.   

    这个是我项目中的一段代码,可以实现对于frame的打印预览,希望对于你有所帮助
    ----------------------
    var strObject="<OBJECT ID=\"pt\" CLASSID=\"CLSID:B43D3361-D975-4BE2-87FE-438AB8E74394\" codebase=\"brochuremachine.cab\" VIEWASTEXT></OBJECT>";
    //var ptc=document.createElement(strObject);
    var printerCTL=oDoc.getElementById("pt");
    try {
    if ( ! printerCTL){
    oDoc.body.insertAdjacentHTML("beforeEnd",strObject);
    }
    var printerCTL=oDoc.all.pt;
    printerCTL.SetFilePath("http://blueswing.vicp.net/PrintTemplate/xp/pt.htm");
    printerCTL.LaunchPT();
    }
    catch(e){
    alert("打印预览过程中出现错误");
    }oDoc就是iframe的document对象,你可以通过对于iframe页面动态插入控件,然后调用其方法来实现的
      

  10.   

    dragon2006(笨龙) 
    我用了你的方法,其中的打印预览无法实现,报错为:未知错误!<input type=button value=打印预览 onclick="document.all.WebBrowser.ExecWB(7,1)">
      

  11.   

    liuruhong(蓝色街灯)
    怎样对iframe页面动态插入控件?
    我的iframe的ID为ifrm1,用ifrm1.body.insertAdjacentHTML("beforeEnd",strObject);提示ifrm1.body为空或不是对象.
      

  12.   

    还有一点:我的iframe中内容多为word文档.
      

  13.   

    怎样在javascript中直接设置好打印方式为横向或纵向,比如:
    <input  type=button value="横向打印"> 
    <input  type=button value="纵向打印">
    不用提示用户再次设置,直接按照按钮提示打印