Home > Web Front-end > JS Tutorial > js implementation of page printing function example code (with header and footer function code attached)_javascript skills

js implementation of page printing function example code (with header and footer function code attached)_javascript skills

WBOY
Release: 2016-05-16 18:39:20
Original
1116 people have browsed it
复制代码 代码如下:







本部分以上不被打印








打印打印打印打印打印打印打印打印



本部分以下不被打印





不打印






打印






-------------
使用JS打印,
看代码
复制代码 代码如下:



这段代码,他是打印

这个标记之间的网页内容。
所以网页中要包含这个2个标签才行···
下面是去除页脚页眉的js代码
复制代码 代码如下:

<script> <br>var HKEY_Root,HKEY_Path,HKEY_Key; <br>HKEY_Root="HKEY_CURRENT_USER"; <br>HKEY_Path="\Software\Microsoft\Internet Explorer\PageSetup\"; <br>//设置网页打印的页眉页脚为空 <br>function PageSetup_Null() <br>{ <br>try <br>{ <br>var Wsh=new ActiveXObject("WScript.Shell"); <br>HKEY_Key="header"; <br>Wsh.RegWrite(HKEY_Root HKEY_Path HKEY_Key,""); <br>HKEY_Key="footer"; <br>Wsh.RegWrite(HKEY_Root HKEY_Path HKEY_Key,""); <br>} <br>catch(e) <br>{} <br><br>} <br><br>//设置网页打印的页眉页脚为默认值 <br>function PageSetup_Default() <br>{ <br>try <br>{ <br>var Wsh=new ActiveXObject("WScript.Shell"); <br>HKEY_Key="header"; <br>Wsh.RegWrite(HKEY_Root HKEY_Path HKEY_Key,"&w&b页码,&p/&P"); <br>HKEY_Key="footer"; <br>Wsh.RegWrite(HKEY_Root HKEY_Path HKEY_Key,"&u&b&d"); <br>} <br>catch(e) <br>{} <br><br>} <br>PageSetup_Default(); <br></script>

注意有可能执行时,会出现没有效果的错误,这时原因是可能你的浏览器限制了active对象的创建,只要取消限制就好了,取消方法如下:

打开你的ie浏览器internet选项—— 安全—— 自定义级别—— 把对没有标记为安全的activex控件进行初始化和脚本运行 设置为启用
更多功能请参考脚本之家现在用的代码。
http://img.jb51.net/inc/content.js
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template