js的页面打印,页眉和页脚一些多余信息怎么去除

Mars大海 2003-07-11 10:44:38
我用了一个打印的控件,然后调用js的print()函数,就打印窗口页面,但是在有些机器上页眉有html里面title的内容打印出来,还有第几页的标识,页脚有该窗口页面的地址打印出来,还有日期,这些信息我都是不需要的,在少数机器上有时就没有,我不知道是什么原因,谁能指点一下是什么的缘故和怎么解决?万分感激!!
...全文
2727 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxf062478 2003-07-11
  • 打赏
  • 举报
回复
解决方案一:
<HTML><HEAD>
<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()
{
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>
</HEAD>

<BODY><br/><br/><br/><br/><br/><br/><p align=center>
<input type="button" value="清空页码" onclick=pagesetup_null()>
<input type="button" value="恢复页码" onclick=pagesetup_default()><br/>
</p></BODY></HTML>
需要将ie安全级别降低,否则创建ActiveXObject对象时会报错。
解决方案二:
使用第三方免费控件
<head>
<title>打印确认</title>
<style media="print">
.noprint { display: none }
</style>
</head>
<body>
<object id="factory" style="display:none" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"></object>
<script defer>
function window.onload() {
//factory.printing.paperSize = "A3"
factory.printing.header = ""
factory.printing.footer = ""
factory.printing.portrait = false
idPrint1.disabled = false; // enable UI button
idPrint2.disabled = false;
idPrint3.disabled = false;
idPrint4.disabled = false;
factory.printing.leftMargin = 0.75
factory.printing.topMargin = 1.5
factory.printing.rightMargin = 0.75
factory.printing.bottomMargin = 1.5
}
</script>
<div class=noprint>
<input id="idPrint1" type="button" value="打印本页"
onclick="factory.printing.Print(false)">
<input id="idPrint2" type="button" value="页面设置"
onclick="factory.printing.PageSetup()">
<input id="idPrint3" type="button" value="打印预览"
onclick="factory.printing.Preview()">
<input id="idPrint4" type="button"
onclick="window.close()" value="关闭窗口">
</div>
<br/>
<table width="720" border="0" cellspacing="0" cellpadding="0" align="center" >
<tr>
<td bgcolor="#0099ff">
这里是你要打印的内容,上面的按钮不会被打印出来<br/>
factory.printing.paperSize = "A3"
</td>
</tr></table></body>
要降低ie的安全级别。

两种方案的缺点都是要降低ie的安全级别,如果不想降低,就不能在代码中实现,而要象上面一样手动更改了。

Mars大海 2003-07-11
  • 打赏
  • 举报
回复
好!谢谢!我还想知道程序里有没有办法,不过能设置已经很好了,我结贴时会给分的
inanition 2003-07-11
  • 打赏
  • 举报
回复
页眉页脚是在浏览器的“文件”--》“页面设置”里面设置的,在程序中如何修改我不太清楚了。
Mars大海 2003-07-11
  • 打赏
  • 举报
回复
good.thx

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧