1.在<head></head>之间加入如下代码;
<OBJECT Classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WB width=0></OBJECT>
<script language=javascript>
function doPrintSetup(){
WB.ExecWB(8,1)
}
function doPrintPreview(){
WB.ExecWB(7,1)
}
</script>
在<body>中调用:
<input type=button name=button1 value="打印设置" onclick="return doPrintSetup()">
<input type=button name=button2 value="打印预览" onclick="return doPrintPreview()">
<input type=button name=button3 value="打印本页" onclick="javascript:print()">
2.在<head></head>之间加入如下代码
<script language="javascript">
function preview()
{
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
//prnform.htext.value=prnhtml;
//prnform.submit();
//alert(prnhtml);
}
</script>
///////
<center>本部分以上不被打印</center>
<!--startprint-->
<table width="84%" align="center" bgcolor="#0000FF" cellpadding="2" cellspacing="1">
<tr bgcolor="#6699FF">
<td>
<div align="center">标题一</div>
</td>
<td>
<div align="center">标题二</div>
</td>
<td>
<div align="center">标题三</div>
</td>
<td>
<div align="center">标题四</div>
</td>
<td>
<div align="center">标题五</div>
</td>
</tr>
<tr bgcolor="#6699FF">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<!--endprint-->
<center>本部分以下不被打印</center>
<div align="center">
<input type="button" name="print" value="预览并打印" onclick="preview()">
</div>
3.其他功能
<input type=button value=刷新 onclick=window.location.reload()>
<input type=button value=前进 onclick=history.go(1)>
<input type=button value=后退 onclick=history.go(-1)>
<input type=button value=前进 onclick=history.forward()>
<input type=button value=后退 onclick=history.back()>
<input type=button value=导入收藏夹 onclick=window.external.ImportExportFavorites(true,"http://localhost");>
<input type=button value=导出收藏夹 onclick=window.external.ImportExportFavorites(false,"http://localhost");>
<input type=button value=整理收藏夹 onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)">
<input type=button value=查看源文件 onclick="window.location = 'view-source:'+ window.location.href">
<input type=button value=语言设置 onclick="window.external.ShowBrowserUI('LanguageDialog', null)">
<input type=button value=加入收藏夹 onclick="window.external.AddFavorite('http://www.microsoft.com/', 'Microsoft Web')">
<input type=button value=加入到频道 onclick="window.external.addChannel('http://www.microsoft.com/')">
<input type=button value=设成主页 onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.microsoft.com/')">
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0 VIEWASTEXT></OBJECT>
<input type=button value=打开 onclick=document.all.WebBrowser.ExecWB(1,1)>
<input type=button value=另存为 onclick=document.all.WebBrowser.ExecWB(4,1)>
<input type=button value=全选 onclick=document.all.WebBrowser.ExecWB(17,1)>
<input type=button value=属性 onclick=document.all.WebBrowser.ExecWB(10,1)>
<input type=button value=关闭窗口 onclick=document.all.WebBrowser.ExecWB(45,1)>
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
<input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
<OBJECT id="min" type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" VIEWASTEXT><PARAM name="Command" value="Minimize"></OBJECT>
<input type=button value="Min" onclick="min.Click()">
<OBJECT id="max" type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT>
<input type=button value="Max/Restore" onclick="max.Click()" id=button1 name=button1>