浏览器打印

/*
 * 2004年12月21日
 * Author:longware< longware@126.com>
 * Usage:<script language="JavaScript" src="./ie6print.js"></script>
 * Note:浏览器需求IE6.0+,在HTTP页面上打印必须将IE的安全级别降低.
 */
document.writeln("<style>");
document.writeln(".btn{font-size:9pt;border-bottom:#cccccc 1px ridge;border-right:#cccccc 1px ridge;border-top:#ffffff 1px ridge;border-left:#ffffff 1px ridge;}");
document.writeln("</style>");
document.writeln("<style media=/"print/">");
document.writeln(".Noprint{display:none;}");
document.writeln(".PageNext{page-break-after: always;}");
document.writeln("</style>");
document.write("<scri");
document.write("pt language=/"JavaS");
document.write("cript/">");
document.writeln("function printSetup(){wb.execwb(8,1);}");
document.writeln("function printPreview(){wb.execwb(7,1);}");
document.writeln("function printNow(){if(confirm('您确定开始打印吗?')){window.print();}}//wb.execwb(6,6);");
document.writeln("function printHelp(){alert(/"如果出现『该页上的 ActiveX 控件不安全』的提示,请将浏览器『Internet选项』中的相关安全设置降低即可。/")}");
document.writeln("</script>");
document.writeln("<div class=/"Noprint/" align=/"right/">");
document.writeln("<br>");
document.writeln("<object classid=/"clsid:8856f961-340a-11d0-a96b-00c04fd705a2/" height=/"0/" width=/"0/" id=/"wb/" name=/"wb/"></object>");
document.writeln("<input type=/"button/" value=/"页面设置/" class=/"btn/" οnclick=/"printSetup();/">&nbsp;");
document.writeln("<input type=/"button/" value=/"打印预览/" class=/"btn/" οnclick=/"printPreview();/">&nbsp;");
document.writeln("<input type=/"button/" value=/"开始打印/" class=/"btn/" οnclick=/"printNow()/">&nbsp;");
document.writeln("<input type=/"button/" value=/"帮助/" class=/"btn/" οnclick=/"printHelp()/" style=/"cursor:help/">&nbsp;");
document.writeln("<input type=/"button/" value=/"关闭窗口/" class=/"btn/" οnclick=/"window.close()/">&nbsp;");
document.writeln("</div>");
控制浏览器打印窗口仅打印是指在网页中使用JavaScript来控制打印行为,仅打印页面中特定的部分,而不是整个页面或者页面中的全部内容。这通常用于将网页上的某个重要部分(如表格、图表或其他数据区域)直接发送到打印机,而忽略页面上的广告、导航栏和其他装饰性内容。 为了实现这个功能,开发者通常会使用`window.print()`方法,它可以触发浏览器打印对话框,然后通过CSS媒体查询或者JavaScript操作来控制打印内容。具体步骤如下: 1. 在CSS中使用媒体查询`@media print`来定义打印时的样式。在这个媒体查询中,可以设置不希望打印的元素的`display`属性为`none`,这样在打印时这些元素就不会出现在打印页面上。 ```css @media print { .non-printable-element { display: none; } } ``` 2. 通过JavaScript的`window.print()`方法触发打印。在触发打印之前,可以使用`window.matchMedia`来检测打印媒体查询是否匹配,以及执行其他需要的打印前操作。 ```javascript if (window.matchMedia('print').matches) { // 执行特定的打印前操作 } window.print(); ``` 3. 在`window.print()`方法之后,可以通过添加事件监听器来处理打印事件,例如监听`beforeprint`和`afterprint`事件来在打印前后执行特定的逻辑。 ```javascript window.addEventListener('beforeprint', function() { // 打印之前的操作 }); window.addEventListener('afterprint', function() { // 打印之后的操作 }); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值