js 连接打印机 去掉页眉页脚
2012-08-24 16:11:55 来源:WEB开发网核心提示: 在web程序中,遇到很多的打印的问题,js 连接打印机 去掉页眉页脚,其中自动去掉页眉页脚也挺重要的,省去了用户的点击流程,打印出想要的东西,整理了《打印预览》《打印》《打印设置》
在web程序中,遇到很多的打印的问题,其中自动去掉页眉页脚也挺重要的,省去了用户的点击流程,打印出想要的东西,整理了《打印预览》《打印》《打印设置》,其中添加了去掉页眉页脚的功能
下面,上代码:
<HEAD>
<TITLE>去网游_www.7wy.net</TITLE>
<META NAME="Generator" CONTENT="">
<META NAME="Author" CONTENT="YC">
<!-- 设置打印的区域-->
<style media="print">
.Noprint{display:none;}<!--用本样式在打印时隐藏非打印项目-->
.PageNext{page-break-after: always;}<!--控制分页--
</style>
<!-- 加载控件 -->
<OBJECT id="WebBrowser"
classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0"></OBJECT>
<script language="JavaScript">
var hkey_root,hkey_path,hkey_key;
hkey_root = "HKEY_CURRENT_USER";
hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
//设置网页打印的页眉页脚为空
function pagesetup_null(){
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,"");
}
//设置网页打印的页眉页脚为默认值s
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){}
}
function PrintPage()
{
pagesetup_null();
document.all.WebBrowser.ExecWB(6,6);
pagesetup_default();
}
function PrintPreview()
{
pagesetup_null();
document.all.WebBrowser.ExecWB(7,1);
pagesetup_default();
}
function PrintSetup()
{
pagesetup_null();
document.all.WebBrowser.ExecWB(8,1);
pagesetup_default();
}
</script>
</HEAD>
<BODY>
<table>
<tr>
<td>1111</td>
<td>1111</td>
</tr>
</table>
<table class="Noprint">
<tr>
<td><input type="button" value="打印" onclick=PrintPage()></td>
<td><input type="button" value="打印预览" onclick=PrintPreview()></td>
<td><input type="button" value="打印设置" onclick=PrintSetup()></td>
</tr>
</p>
</BODY>
</HTML>
更多精彩
赞助商链接
