在网页上显示出来以后,点击打印按钮生成预览并打印,不同的浏览器的实现方式略有不同。
IE:自带打印功能 详见博客--->点击打开链接 据说高版本的IE不支持WebBrowser控件了
<body style="font:14px;">
<center class="Noprint">
<br />
<object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0">
</object>
<input type="button" value="打印" οnclick="document.all.WebBrowser.ExecWB(6,1)" />
<input type="button" value="直接打印" οnclick="document.all.WebBrowser.ExecWB(6,6)" />
<input type="button" value="页面设置" οnclick="document.all.WebBrowser.ExecWB(8,1)" />
<input type="button" value="打印预览" οnclick="document.all.WebBrowser.ExecWB(7,1)"/>
<hr align="center" width="90%" size="1" />
</center>
<form id="form2" runat="server">
<asp:Label runat="server" ID="lblTable"></asp:Label>
</form>
</body>
Chrome:直接用一个window.open()就行
<input type="button" value="打印" οnclick="window.open()"/>
还可以整合起来,通过判断来选择用哪种方法
<script type="text/javascript">
function foo(a,b)
{
if (window.navigator.userAgent.indexOf("Chrome") !== -1)
{ WebBrowser.Execwb(a, b); }
else { window.print(); }
}
</script>
<input type="button" value="打印" οnclick="foo(6,1)"/>
详见----> 点击打开链接
插件了解一下:http://www.lodop.net/LodopDemo.html