實現打印的幾種方式

1.        調用frmae 執行print命令          idFrame.document.execCommand('print');

 

源碼:

<html>
<head>
<title>
</title>
<style>
html      { font: 9pt / 13pt Verdana; color: black }
input        { font: 9pt Verdana; color: black; width: 115pt }
input.ie55   { display: none }
body         { background-color: gainsboro; padding: 10pt }
li      { margin-top: 4pt }
p            { margin-top: 6pt; margin-bottom: 6pt }
h2      { font:bold 16pt / 18pt Verdana }
</style>
<!-- special style sheet for printing -->
<style media="print">
.noprint     { display: none }
</style>
</head>
<body>
<object id="WebBrowser" width=0  height=0  classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
<SCRIPT language=javascript>
function printpr() //打印預覽   、
{  
 var obj=document.getElementById("idFrame");
  obj.focus();   
  WebBrowser.ExecWB(7,1);

function pagesetup() //頁面設置
{  
 var obj=document.getElementById("idFrame");
  obj.focus();
  WebBrowser.ExecWB(8,1);

function printTrue() //打印 
{  
  var obj=document.getElementById("idFrame");
  obj.focus();
  idFrame.document.execCommand('print');
}   
 
</SCRIPT>    
<div id=idControls class="noprint">
 <input type="button" onClick="printpr();" value="打印預覽">
 <input type="button" onClick="pagesetup();" value="頁面設置">
 <input type="button" onClick="printTrue();" value="打印">
<input  type="button" value="關閉窗口" οnclick="window.close();">  
</div>
<iframe name="idFrame" width="100%" src="http://www.163.com" frameborder="0" id="idFrame" scrolling="no"

marginheight="0" marginwidth="0" οnlοad="this.height=idFrame.document.body.scrollHeight"></iframe>
</body>
</html>

 

2.直接 window.print();

 

 

function printDoc()
{
 document.getElementById("printbtn").style.display = "none";
 document.getElementById("closebtn").style.display = "none";
 window.print();
 document.getElementById("printbtn").style.display = "";
 document.getElementById("closebtn").style.display = "";
}

發佈了103 篇原創文章 · 獲贊 0 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章