<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test12.aspx.cs" Inherits="test12" %>
<!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 language="javascript" type="text/javascript">
// <!CDATA[
function printform(){
var printContent = document.getElementById("<%= pnlPrint.ClientID %>");
var windowUrl = 'about:blank';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName);
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
function Button1_onclick()
{
printform();
}
function Button2_onclick() {
var iframe = document.getElementById("ifMain");
if (iframe && iframe.contentWindow) {
iframe.contentWindow.focus();
iframe.contentWindow.print();
}
}
// ]]>
</script>
</head>
<body>
<input id="btnPrint" runat="server" onclick="return Button1_onclick()" type="button" value="列印" />
<input id="Button1" runat="server" onclick="return Button2_onclick()" type="button" value="列印iframe" />
<asp:Panel ID="pnlPrint" runat="server">
<span>聖馬爾定醫院</span>
列印內容
</asp:Panel>
<iframe id="ifMain" src="test07.htm"></iframe>
</body>
</html>