日期:2014-05-20  浏览次数:20790 次

js实现打印预览及打印
<HTML>
<HEAD>
<TITLE>學習打印、預覽</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8" />
<SCRIPT language=javascript> 
 
function printsetup(){
  wb.execwb(8,1); 
}
function printpreview(){

  var wb = document.getElementById("wb");
  wb.execwb(7,1);
}
function printit(){
 if (confirm("确定打印吗?")){
    wb.execwb(6,6) 
 }
}
</SCRIPT>
</HEAD>
<BODY>

<DIV align=center>
<OBJECT id="wb" height='0' width='0' 
classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" name="wb"></OBJECT>
<INPUT onclick="printit();" type=button value="打印" name="button_print" /> 
<INPUT onclick="printsetup();" type=button value="打印页面设置" name="button_setup" /> 
<INPUT onclick="printpreview();" type="button" value="打印预览" name="button_show" /> 
</DIV>
</BODY>
</HTML>

========================================第二種=====================================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function preview(oper){
 if (oper < 10){
  bdhtml = window.document.body.innerHTML;//获取当前页的html代码
  sprnstr = "<!--startprint"+oper+"-->";//设置打印开始区域
  eprnstr = "<!--endprint"+oper+"-->";//设置打印结束区域
  prnhtml = bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html

  prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
  window.document.body.innerHTML=prnhtml;
  window.print();
  //window.document.body.innerHTML=bdhtml;
} else{
 window.print();
}
}
</script>
</HEAD>

<BODY>
<!-- 将页面内要打印的内容加入中间 -->如打印hello World!!

<!--startprint1-->hello World!!<!--endprint1-->
<!-- 再加个打印按纽 -->

<input type="button" onclick='preview(1);' value="preview">
</BODY>
</HTML>



------解决方案--------------------
不知道是啥意思,
是分享打印方法吗?