" height="0"><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=关闭>
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;
}
<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>
<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中打印网页实在是太简单不过了。只需点一下工具栏上“打印”按钮就可将当前网页打印出来。如下图所示:
cript网页打印大全 - 心雨 - 心雨" height=100 alt="Javascript网页打印大全 - 心雨 - 心雨" src="https://cqzx.sdedu.net/sdms/images/guide1.JPG" width=600 border=0>
不 过,你这样打出来的效果怎么样呢?我就不敢说了。我今天要和大家讲的就是一些打印方面的设置参数。如何大家把这些参数设置好,你就会发现IE的打印功能 快追得上Word了。今后你打印网页时就可以想怎么打就怎么打了。好,闲话少说,现在就跟我来一起看看怎么样设置IE的打印参数。
我们以下图要打印的学生名单(《学生学籍管理系统MX》查询结果网页)为例,讲解如何设置这些打印参数:
cript网页打印大全 - 心雨 - 心雨" height=298 alt="Javascript网页打印大全 - 心雨 - 心雨" src="https://cqzx.sdedu.net/sdms/images/guide2.JPG" width=400 border=0>
假如我们直接点工具栏的“打印”按钮或点“文件”菜单中的“打印”进行打印这个网页的话,就会打印出很多不必要的信息。所以在打印前我们应先用IE5新增的“打印预览”功能查看当前网页的实际打印效果。如下图所示:
cript网页打印大全 - 心雨 - 心雨" height=254 alt="Javascript网页打印大全 - 心雨 - 心雨" src="https://cqzx.sdedu.net/sdms/images/guide3.JPG" width=600 border=0>
在如下图所示的“打印预览”对话框中,我们可以看到,网页标题、网页的URL地址及打印日期等我们所不需要的信息也被打印出来了。而页码又在右上角,能不能把它移到其他位置(如我们常见的右下角)呢?
cript网页打印大全 - 心雨 - 心雨" height=274 alt="Javascript网页打印大全 - 心雨 - 心雨" src="https://cqzx.sdedu.net/sdms/images/guide4.JPG" width=600 border=0>
cript网页打印大全 - 心雨 - 心雨" height=274 alt="Javascript网页打印大全 - 心雨 - 心雨" src="https://cqzx.sdedu.net/sdms/images/guide5.JPG" width=600 border=0>
能不能按照我们所想要的样式来打印网页呢?当然可以。一切就在“页面设置”中。
cript网页打印大全 - 心雨 - 心雨" height=255 alt="Javascript网页打印大全 - 心雨 - 心雨" src="https://cqzx.sdedu.net/sdms/images/guide6.JPG" width=600 border=0>
弹出如下图所示的“页面设置”对话框,所有的秘密都在这里!
cript网页打印大全 - 心雨 - 心雨" height=382 alt="Javascript网页打印大全 - 心雨 - 心雨" src="https://cqzx.sdedu.net/sdms/images/guide7.JPG" width=393 border=0>
原 来,IE自动给我们在页眉和页脚处加上了这些不必要的打印信息。如果我们不想要任何页眉和页脚的话,直接删除它们就行了。:-)大部分时候我都是这样做 的。但如果你想自定义页眉和页脚的时候,该怎么做呢?上面的那些“&w&b&p”等等究竟表示什么意思呀?给你个表格就知道了。 符号含义
&w |
网页标题 |
&u |
网页地址 (URL) |
&d |
短日期格式(由“控制面板”中的“区域设置”指定) |
&D |
长日期格式(由“控制面板”中的“区域设置”指定) |
&t |
由“控制面板”中的“区域设置”指定的时间格式 |
&T |
24 小时时间格式 |
&p |
当前页码 |
&P |
总页数 |
&b |
文本右对齐(请把要右对齐的文字放在“&b”之后) |
&b&b |
文字居中(请把要居中的文字放在“&b”和“&b” 之间) |
&& |
单个 & 号 (&) |
注:1、这些符号可以与文字组合使用,如本教程中的“页码,&p/&P”。
2、页眉和页脚默认是左对齐的,所以IE只提供了右对齐和居中的设置符号。
3、推荐给大家一种设置方法:页眉为空,页脚设为“&b第 &p 页 / 共 &P 页&b”,打印效果为在页脚居中显示“第 1 页 / 共 4 页”的效果。
知 道了上面的知识,你就可以打印了。但有时你会发现,网页中的一些图像在打印时不见了。Why?为什么会这样?别着急,IE的默认设置是不打印网页的背景 颜色和图像的。您只需进入IE的Internet选项将它选中(打上勾)就行了。具体操作方法是:点IE的主菜单中的“工具”——“Internet选 项”——再在弹出的对话框中占击“高级”选项卡,找到“打印背景颜色和图像”一项。如下图所示:
cript网页打印大全 - 心雨 - 心雨" height=369 alt="Javascript网页打印大全 - 心雨 - 心雨" src="https://cqzx.sdedu.net/sdms/images/guide8.JPG" width=350 border=0>
然后将上图中红色圈住的选项打上勾,再点“确定”就OK了。
至此,我们就完成了对IE的打印设置。接下来,只要我们没有关闭IE,我们就可以一直使用上述设置(最后一项“打印背景颜色和图像”的更改始终有效)进行打印。打印前一般先进行打印预览,效果满意后再开始打印。
自己曾经用过的打印
JS 实现简单的页面局部打印
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();
}
}
使用很简单 将页面内要打印的内容加入中间<!--startprint1-->XXXXX<!--endprint1-->
再加个打印按纽 onclick=preview(1)