- 浏览: 1468176 次
- 性别:
- 来自: 大连
文章分类
- 全部博客 (460)
- java (148)
- javascript (34)
- Flex文章 (4)
- css+div (2)
- ajax (6)
- extjs (11)
- 人生感悟 (9)
- struts2.0 (6)
- IT之路,生活 (15)
- hibernate (6)
- struts1 (1)
- spring (5)
- j2ee错误 (3)
- Dwr (5)
- Linux (33)
- C++ (3)
- SWT Win32 (2)
- EJB (1)
- JPA (4)
- C语言和LinuxC (7)
- SQL (13)
- 项目经理 (6)
- db2 (2)
- java数据结构 (2)
- 网页播放器flv (1)
- 数据库 (24)
- 用户体验设计学习 (2)
- 网络电话 (5)
- 军事理论 (4)
- android (3)
- oracle (18)
- oracle ebs form (11)
- oracle ebs oaf (4)
- erp (20)
- DBA (9)
- java中URL 的编码和解码函数 (1)
- 铁血丹心 (1)
- excel 单元格格式不能立即生效 (1)
- Java调用bat文件 (1)
- 如何把本地outlook中的邮件上传到网络邮箱中 (1)
- java 报表 打印 (1)
- 创建dblink (1)
- 图标前台框架 (1)
- vnc (1)
- FORM (1)
- MYSQL (1)
最新评论
-
July01:
推荐用StratoIO打印控件,支持网页、URL、图片、PD、 ...
web打印不显示页眉页脚 -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
Javascript网页打印大全 -
hardyer:
大哥写的很实在,受教了,提前祝你元旦快乐!
黎活明给程序员的忠告 -
cxysilahi:
请问WIN7 64位,调用报错Exception in thr ...
JNative的初步使用 -
action1949:
好东西,解决问题
JFreeChart乱码解决方法
一、普通打印(整页打)
二、打印网页内部分内容(自定义)
三、打印去掉/添加页眉页脚
四、使用外部控件/方法实现多功能打印
五、打印背景
(以上为代码控制)
六、设置“页面设置”实现打印参数设置(Window系统图文版)
一、普通打印(整页打)
这个不用多说,直接用
引用:window.print();
二、打印网页内部分内容(自定义)
分三种方法实现:
1、用css控制
引用:@media print
.a {display:block}
.b {display:hidden}
把你不想打印的部分class设为b
首先在网页中添加:
引用:<OBJECT id="WebBrowser" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"
VIEWASTEXT>
</OBJECT>
然后就可以依次加入功能按钮了:
引用:<input type="button" value="打印"> <input type="button" value="直接打印">
<input type="button" value="页面设置">
<input type="button" value="打印预览"> <INPUT type="button" value="关闭窗口" >
将这两块东西放到<center class=noprint></center>就不会打印这些按钮了。当然要定义noprint了:
<style media="print">.Noprint { DISPLAY: none }</style>只要把不想打印的东西的css设置成noprint就可以了。
现在就实现了基本的web打印,需要注意的情况如下:
a. 必须将ie的internet选项的安全设置中对于没有标记为安全的ActiveX控件进行...设置成提示或者启用,否则会报错,导致不可用。
b. 如果在vs.net编辑环境下编辑该页面,它经常自动的给object添加多余的参数,有了这些东西,打印就会出错,所以要记得最后保存的时候删除它们。
2、用javascript打印固定标签内的内容
a、在页面的代码头部处加入JavaScript:
引用:<script language=javascript>
function doPrint() {
bdhtml=window.document.body.innerHTML; //获取当前页的html代码
sprnstr="<!--startprint-->"; //设置打印开始区域
eprnstr="<!--endprint-->"; //设置打印结束区域
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); //从开始代码向后取html
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); //从结束代码向前取html
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
b、在页面正文处加上<!--startprint-->与<!--endprint-->标识。
也就是在需要用户打印保存的正文所对应的html处附加上。同时,如果采用小偷程序获得远程数据并需打印,可将此等数据置于该定义标签之内即可。
3、截取内容部分已完成,现在加个“打印”的链接:
XML/HTML代码
<a href="javascript:;" onClick="doPrint()">打印</a>
引用:
<script language="JavaScript">
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="file://Software//Microsoft//Internet Explorer\\PageSetup\\"
//设置网页打印的页眉页脚为空
function pagesetup_null(){
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
}catch(e){}
}
//设置网页打印的页眉页脚为默认值
function pagesetup_default(){
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P")hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d")
}catch(e){}
}
</script>
<input type="button" value="清空页码" onclick=pagesetup_null()>
<input type="button" value="恢复页码" onclick=pagesetup_default()>
复制出去,看下效果就可以了
四、使用外部控件/方法实现多功能打印
1、IEWebBrowser组件
介绍
http://support.microsoft.com/default.aspx?scid=kb%3BEN-US%3BQ267240#top
http://support.microsoft.com/kb/q247671/#appliesto
代码
引用:<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>
<input name=Button onClick=document.all.WebBrowser.ExecWB(2,1) type=button value=关闭所有>
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为>
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,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(7,1) type=button value=打印预览>
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置>
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性>
<input name=Button onClick=document.all.WebBrowser.ExecWB(17,1) type=button value=全选>
<input name=Button onClick=document.all.WebBrowser.ExecWB(22,1) type=button value=刷新>
<input name=Button onClick=document.all.WebBrowser.ExecWB(45,1) type=button value=关闭>
2、使用ScriptX.cab控件
1.下载ScriptX.cab控件
官网http://www.meadroid.com/scriptx/index.asp
2.使用object元素,修改codebase,classid的值
这里调用控件ScriptX.cab
代码
引用:
<OBJECT id="factory" style="DISPLAY: none" codeBase="${rootUrl}js/smsx.cab#VVersion=6,3,435,20" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext></OBJECT>
这段代码用来加载cab文件,clsid和codebase必须要和你下载的cab中的信息对应,否则组件会加载错误,这两项其实不难找,只要你用winrar打开你下载的cab文件,然后找到扩展名是.inf的文件,然后打开之,就能看到了。
3.调用控件脚本
Print.js文件
代码
引用:
function setPrintBase(headerText,footerText,rootUrl) {
// -- advanced features ,未曾使用过,有待确认。
//factory.printing.SetMarginMeasure(2); // measure margins in inches
//factory.SetPageRange(false, 1, 3);// need pages from 1 to 3
//factory.printing.printer = "HP DeskJet 870C";
//factory.printing.copies = 2;
//factory.printing.collate = true;
//factory.printing.paperSize = "A4";
//factory.printing.paperSource = "Manual feed"
var header = (headerText==null||headerText=="")?'默认页眉':headerText;
var footer = (footerText==null||footerText=="")?'默认页角':footerText;
factory.printing.header = "&b"+header+"&b" ;
factory.printing.footer = "&b"+footer;
factory.printing.portrait = true;
factory.printing.leftMargin =10.00;
factory.printing.topMargin =10.00;
factory.printing.rightMargin =10.00;
factory.printing.bottomMargin =10.00;
}
例子
引用:
<html>
<head>
<meta http-equiv="imagetoolbar" c>
<script language="javascript" src="print.js"></script>
<style media="print">
.Noprint {DISPLAY: none;}
</style>
<title>打印测试</title>
</head>
<OBJECT id="factory" style="DISPLAY: none" codeBase="smsx.cab#VVersion=6,3,435,20" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext></OBJECT>
<script defer>
function window.onload() {
setPrintBase('页眉','页脚');
}
</script>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<center class="Noprint">
<input type=button value="打印" >
<input type=button value="页面设置" >
<input type=button value="打印预览" >
<input type="button" value="关闭" >
</center>
<center>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align="center"><b>内容</b></td></tr>
</table>
</center>
</body>
</html>
五、打印背景
默认情况下,使用IE浏览器打印网页时,不打印网页背景。如果需要打印网页背景,可以采用如下的方法设置:
1. 启动IE浏览器。
2. 选择【工具】菜单中的【Internet选项】菜单项,打开【Internet选项】对话框。
3. 打开【高级】选项卡,在【打印】选区中选择【打印背景颜色和图像】复选框。
4. 单击【确定】按钮,关闭对话框。
六、如何用IE打印网页
Internet Explorer(简称IE)5.0以上版本强大的打印及打印预览功能。本文就向大家介绍如何用IE来打印网页。(谁?谁?谁在扔西红柿?下面一片嘘声: 这还用得着你讲呀?!)咳咳咳,是的是的,在IE中打印网页实在是太简单不过了。只需点一下工具栏上“打印”按钮就可将当前网页打印出来。如下图所示:
使用js打印局部页面
<script type="text/javascript">
///***********************
///打印指定区域页面
///说明:obj–通过getElementById或其它方式获取标签标识,打印此obj内的文字
///开发:王洪剑http://www.cnblogs.com/walkingp/archive/2009/08/07/1541060.html
///日期:2009-8-7htt//read.jydsj.com/read/show.asp?show=pre&xid=402&nid=203921
function startPrint(obj)
{
var oWin=window.open("","_blank");
var strPrint="<h4 style=’font-size:18px; text-align:center;’>打印预览区</h4>\n";
strPrint=strPrint + "<script type=\"text/javascript\">\n";
strPrint=strPrint + "function printWin()\n";
strPrint=strPrint + "{";
strPrint=strPrint + "var oWin=window.open(\"\",\"_blank\");\n";
strPrint=strPrint + "oWin.document.write(document.getElementById(\"content\").innerHTML);\n";
strPrint=strPrint + "oWin.focus();\n";
strPrint=strPrint + "oWin.document.close();\n";
strPrint=strPrint + "oWin.print()\n";
strPrint=strPrint + "oWin.close()\n";
strPrint=strPrint + "}\n";
strPrint=strPrint + "<\/script>\n";
strPrint=strPrint + "<hr size=’1′ />\n";
strPrint=strPrint + "<div id=\"content\">\n";
strPrint=strPrint + obj.innerHTML + "\n";
strPrint=strPrint + "</div>\n";
strPrint=strPrint + "<hr size=’1′ />\n";
strPrint=strPrint + "<div style=’text-align:center’><button onclick=’printWin()’ style=’padding-left:4px;padding-right:4px;’>打 印</button><button onclick='window.opener=null;window.close();' style='padding-left:4px;padding-right:4px;'>关 闭</button></div>\n";
oWin.document.write(strPrint);
oWin.focus();
oWin.document.close();
}
</script>
<button id="btnPrint" onclick="startPrint(document.getElementById(’content’))">打印内容</button>
<div id="content">
<div style="font-size:12px;color:#333;">
这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容这里是打印内容
</div>
</div>
评论
发表评论
-
Oracle Developer10G 安装
2020-09-09 18:03 331oracle 客户端也要删除,以前的oracle产品 ... -
打开Eclipse时出现"The Eclipse executable launcher was unable to locate its companion
2018-06-05 15:06 9602打开Eclipse时出现"The Eclipse ... -
J2EE通过tomcat部署的两种方式
2017-09-12 09:01 657转载:http://blog.csdn.net/psp000 ... -
Linux安装Tomcat7
2016-03-30 15:01 868http://blog.sina.com.cn/s/blog ... -
java支持跨平台获取cpuid、主板id、硬盘id、mac地址 (兼容windows、Linux)(转)
2015-11-17 22:10 1539http://blog.csdn.net/flyingclo ... -
栋哥涕啐茆
2015-10-27 10:49 753栋哥涕啐茆 -
Eclipse快捷键 10个最有用的快捷键
2015-10-27 10:18 786Eclipse中10个最有用的快捷键组合 一个Eclip ... -
java上传头像图像剪切
2015-04-02 20:19 1161java上传头像图像剪切 JQUERY 图片上传裁切 -
创建dblink
2014-12-11 20:01 670CREATE public database link ... -
Bitnami Redmine 安装笔记
2014-12-10 11:28 1591http://atian25.iteye.com/blog/ ... -
利用workflow发送类似数据报表内容的通知页面
2014-11-21 15:03 811利用workflow发送类似数据报表内容的通知页面 ... -
excel科学技术法问题
2014-11-12 13:50 7841.使用导入外部数据的方法2.并且在第三步的时候选择文本,需要 ... -
java.lang.IllegalAccessError
2014-09-29 11:05 1133java.lang.IllegalAccessError: ... -
java如何获取文件编码格式
2014-04-11 11:28 102171:简单判断是UTF-8或不是UTF-8,因为一般除了UTF ... -
JAVA中使用FTPClient上传下载
2013-12-08 13:35 1911方法一:这种方法网上有许多 可以用下面的方式,但是支持批量 ... -
在Java中获取环境变量
2013-11-11 11:18 1418package cy.cn.test; import ... -
ORACLE性能调整笔记
2013-11-05 18:39 0一 关于statspack中等待事件的一些解释 ... -
EBS DBA指南笔记1
2013-11-05 18:35 1895时光飞逝,不从事EBS DBA转眼已有两年多。很还念那段学习 ... -
用html代码在word中插入分页符和页面设置
2013-11-05 17:11 5277<span lang=EN-US style=&quo ... -
OpenJWeb新增二维码图片生成功能
2013-11-05 09:02 1269在开发进销存软件的时 ...
相关推荐
Javascript网页打印大全(有图版)
源代码:javascript网页打印设置
利用javascript在网页上实现打印的方法,可以设置分页等页面设置。
用Javascript打印网页指定标签的内容
javascript打印网页中指定部分的内容
常用的网页打印的方法,非常不错,可以设置打印区域
javascript打印网页,ajax处理数据
js实现的网页打印效果,本人亲自编写。在谷歌浏览器下亲测可用,欢迎下载!
实例291 调用IE自身的打印功能实现打印 460 实例292 打印指定框架中的内容 461 实例293 利用WebBrowser打印 462 实例294 设置页眉页脚 463 11.2 利用Word打印报表 465 实例295 将页面中的表格导出到Word并打印 465 ...
5.8 双击后,网页自动滚屏 6、树型结构。 6.1 asp+sql版 6.2 asp+xml+sql版 6.3 java+sql或者java+sql+xml 7、无边框效果的制作 8、连动下拉框技术 9、文本排序 10,画图类,含饼、柱、矢量贝滋曲线 11...
8.10 单击按钮打印当前页面 217 8.11 记录用户的来访次数 218 8.12 可选择的页面信息 219 8.13 文本框消失的页面 220 8.14 随机播放背景音乐的页面 221 8.15 能自动滚屏的页面 222 8.16 密码保护页面 223 ...
这个是用JavaScript写成的,纯客户端程序.......
实例291 调用IE自身的打印功能实现打印 460 实例292 打印指定框架中的内容 461 实例293 利用WebBrowser打印 462 实例294 设置页眉页脚 463 11.2 利用Word打印报表 465 实例295 将页面中的表格导出到Word...
JsPrint网页打印控件,引用一个JS直接调用方法,就可打印指定的DIV内容。
DHTML 手册 JavaScript网页设计300例 分页.sql 万年历查询 数据库操作类 导出Excel 打印浏览类
JavaScript网页特效范例宝典 Script在网站开发中各个方面的常用技术和技巧。全书共19章,分别是窗口/框架与导航条设计、表单及表单元素、实用JavaScript函数、日期和时间、文字特效、超级链接特效、操作表格、图形...
在各种动态网页开发语言下使用VBScript、JavaScript脚本语言进行各种信息的打印预览工作,可以直接打印HtmlTable网页元素中的文字信息。 在控件演示实例中有本控件的详细说明文件,本控件现在是打印预览控件的测试...
打印网页格式的票据,报表等; 打印Web上的 Word、Excel、PowerPoint、WPS、PDF文档; 通过 Javascript API 实现一键打印,无须人工干预; 让用户运行时调整打印位置; 实现打印内容的 PDF 导出等。; 杰表云打印是在...
分别是窗口/框架与导航条设计、表单及表单元素、实用JavaScript函数、日期和时间、文字特效、超级链接特效、操作表格、图形图像与多媒体、页面特效、状态栏特效、报表与打印、网站安全、HTML/CSS样式、JavaScript与...
仅打印网页内的文字.rar仅打印网页内的文字.rar仅打印网页内的文字.rar仅打印网页内的文字.rar仅打印网页内的文字.rar仅打印网页内的文字.rar