当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 用javascript实现页面打印的三种方法

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 用javascript实现页面打印的三种方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 132 ::
收藏到网摘: n/a

前一段时间听朋友说起过打印网页的一些方法,在安静的夜晚,听着歌曲无意间发现了几段代码,帖出来跟大家分享一下。
因为我从来没有打印过网页,而且也没有打印机,具体的效果也不是很清楚,测试打印成PDF是正常的,就第二种在弹出设置窗口比第一跟第三种方法多了点。
注意:第二种方法的控件需要IE5.5+的支持,而且因为使用了控件,如果客户端IE的安全性设置过高,将无法正常运行。
特别提示
运行本例代码,如果已经安装了打印机,将直接调用打印机打印页面,否则提示安装打印机。
1.用window对象的print方法

<button onClick="window.print()">打印</button>
2.用WebBrowser控件

<object id="WebBrowser" width=0 height=0
classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
<button onClick="WebBrowser.ExecWB(8,1)">打印</button>
3.在文档区域执行print命令

<button onClick="document.execCommand('print')">打印</button>