web打印,巧妙实现隐藏不想打印的页面元素,以及页眉和页脚

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 enjsky 的 blog


<html><head><title>web打印去掉页眉页脚,以及不想打印出的页面元素</title>
<meta http-equiv=content-type content="text/html; charset=gb2312">
<script language=javascript>
function printpr()   //预览函数
{
document.all("qingkongyema").click();//打印之前去掉页眉,页脚
document.all("dayindiv").style.display="none"; //打印之前先隐藏不想打印输出的元素(此例中隐藏“打印”和“打印预览”两个按钮)
var olecmdid = 7;
var prompt = 1;
var webbrowser = '<object id="webbrowser1" width=0 height=0 classid="clsid:8856f961-340a-11d0-a96b-00c04fd705a2"></object>';
document.body.insertadjacenthtml('beforeend', webbrowser);
webbrowser1.execwb(olecmdid, prompt);
webbrowser1.outerhtml = "";
document.all("dayindiv").style.display="";//打印之后将该元素显示出来(显示出“打印”和“打印预览”两个按钮,方便别人下次打印)
}

function printture()   //打印函数
{
    document.all('qingkongyema').click();//同上
    document.all("dayindiv").style.display="none";//同上
    window.print();
    document.all("dayindiv").style.display="";
}
function dopage()
{
    layloading.style.display = "none";//同上
}

</script>

<script language="vbscript">
dim hkey_root,hkey_path,hkey_key
hkey_root="hkey_current_user"
hkey_path="\software\microsoft\internet explorer\pagesetup"
'//设置网页打印的页眉页脚为空
function pagesetup_null()
on error resume next
set regwsh = createobject("wscript.shell")
hkey_key="\header"
regwsh.regwrite hkey_root+hkey_path+hkey_key,""
hkey_key="\footer"
regwsh.regwrite hkey_root+hkey_path+hkey_key,""
end function
'//设置网页打印的页眉页脚为默认值
function pagesetup_default()
on error resume next
set regwsh = createobject("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"
end function
</script>

</head>
<body background="images/background_01.gif" leftmargin=0
topmargin=0 rightmargin=0 bottommargin=0 style="background-position: center 50%">

<div align=center>
 
 你希望打印的内容..........
 </div>

<div align="center" id="dayindiv" name="dayindiv"><input type="button" class="tab" value="打印" onclick="printture();">&nbsp;&nbsp;
<input  type="button" class="tab" value="打印预览" onclick="printpr();">
<input type="hidden" name="qingkongyema" id="qingkongyema" class="tab" value="清空页码" onclick="pagesetup_null()">&nbsp;&nbsp;
<input type="hidden" class="tab" value="恢复页码" onclick="pagesetup_default()">
</div>

</body>
</html>


本文关键:web打印,巧妙实现隐藏不想打印的页面元素,以及页眉和页脚
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top