javascript:window.print()
列印
1.JavaScript列印
<input id="btnPrint" type="button"
value="button" onclick="javascript:window.print();"
style="color:#00f;
font-weight:bold; text-decoration:none;cursor:pointer!important;
cursor:hand"/>
可以用樣式控制,你想讓那塊列印就列印,樣式如下:
<style type="text/css" media=print>
.noprint{display : none }
</style>
然後使用樣式就可以:
<p class="noprint">不需要列印的地方</p>
如果要列印網頁中的某一部分,只要把這一部分標記為
<!--startprint--><!---endprint-->中就可以了
=============================================================
2.IE列印
<script language="javascript">
// 列印版面設定
function printsetup() { wb.execwb(8,1);}
// 列印頁面預覽
function printpreview() { wb.execwb(7,1); }
function printit(){ if (confirm('確定列印嗎?')) {
wb.execwb(6,6) }}
</script>
</head>
<body>
<OBJECT classid="CLSID:8856F961_340A_11D0_A96B_00C04FD705A2"
<link rel=alternate media=print
href="printversion.doc"> height=0 id=wb name=wb
width=0></OBJECT>
<input type=button name=button_print
value="列印"
onclick="javascript:printit()">
<input type=button name=button_setup
value="列印版面設定"
onclick="javascript:printsetup();">
<input type=button name=button_show
value="預覽列印" onclick="javascript:printpreview();">
<input type=button name=button_fh
value="關閉"
onclick="javascript:window.close();">
------------------------------------------------
關於這個組件還有其他的用法,列舉如下:
WebBrowser.ExecWB(1,1) 開啟
Web.ExecWB(2,1) 關閉現在所有的IE視窗,並開啟一個新視窗
Web.ExecWB(4,1) 儲存網頁
Web.ExecWB(6,1) 列印
Web.ExecWB(7,1) 預覽列印
Web.ExecWB(8,1) 列印版面設定
Web.ExecWB(10,1) 查看頁面屬性
Web.ExecWB(15,1) 好像是撤銷,有待確認
Web.ExecWB(17,1) 全選
Web.ExecWB(22,1) 重新整理
Web.ExecWB(45,1) 關閉表單無提示
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Dept_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function printpage()
{
document.getElementById("noprint").style.display="none";//列印整個頁麵包括標題,在調用列印方法之前隱藏不需要列印的頁面標籤。無標題將不列印標題
print();
}
function printsetup()
{
try
{
document.all.WebBrowser.ExecWB(8, 1);
}
catch(e)
{
//ymPrompt.errorInfo({title:SYS_NAME,
message:'版面設定需要ActiveX, 請允許本網站使用ActiveX'});
}
printpage();
}
</script>
</head>
<body>
<object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0"
width="0" viewastext>
</object>
<form id="form1" runat="server">
<font color="red">打 印打 印打 印<br />點點滴滴</font> dfdsfdsfds
<div>
<input type="button" value="打 印" id="noprint" class="btnnm" onmouseover="this.className='btnon'"
onmouseout="this.className='btnnm'" onclick="printsetup();" />
</div>
</form>
</body>
</html>