在PHP裡的JS列印函數
auto=1立即PRINT,否則timeOut毫秒後PRINT,如printPage(0,5000);
function printPage($auto=1,$timeOut=10000) {
if ($auto == 1) {
echo "
< language="JavaScript">
< !-- Begin if (window.print) { window.print(); } else { alert('No printer driver in your PC'); } // End -- >
< /script >
n";
}
else {
echo "
< language="JavaScript">
< !-- Begin if (window.print) { setTimeout('printCheck()','$timeOut'); } else { alert('No printer driver in your PC'); } function printCheck() { agree = confirm('OK to print now?'); if (agree) window.print(); } // End -- >
< /script >
n";
}
}
==================================================
整頁列印:
html部分:
<INPUT TYPE="button" value="整頁列印" onclick="print()">
Javascript部分:
N/A
部分列印(只列印div包起來的網頁):
html部分:
<div id="block">
<P><img id="ruten" name="ruten" SRC="http://www.ruten.com.tw/imgs/2008/logo.gif"></P>
</div>
<input type="button" value="部分列印" onclick="printScreen(block)">
Javascript部分:
//列印div包起來的部分並且列印完畢後自動關閉列印網頁
function printScreen(block){
var value = block.innerHTML;
var printPage = window.open("","printPage","");
printPage.document.open();
printPage.document.write("<HTML><head></head><BODY onload='window.print();window.close()'>");
printPage.document.write("<PRE>");
printPage.document.write(value);
printPage.document.write("</PRE>");
printPage.document.close("</BODY></HTML>");
}
整頁預覽列印:
html部分:
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<INPUT TYPE="button" value="整頁預覽" onclick="javascript:wb.execwb(7,1)">
Javascript部分:
N/A
部分預覽列印(只預覽div包起來的部份):
html部分:
<div id="block">
<P><img id="ruten" name="ruten" SRC="http://www.ruten.com.tw/imgs/2008/logo.gif"></P></div>
<input type="button" value="區塊預覽" onclick="previewScreen(block)">
Javascript部分:
//預覽div包起來的部分並且列印完畢後自動關閉列印網頁
function previewScreen(block){
var value = block.innerHTML;
var printPage = window.open("","printPage","");
printPage.document.open();
printPage.document.write("<OBJECT classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2' height=0 id=wc name=wc width=0></OBJECT>");
printPage.document.write("<HTML><head></head><BODY onload='javascript:wc.execwb(7,1);window.close()'>");
printPage.document.write("<PRE>");
printPage.document.write(value);
printPage.document.write("</PRE>");
printPage.document.close("</BODY></HTML>");
}
沒有留言:
張貼留言