JS列印相關內容

來源:互聯網
上載者:User

使用WebBrowser控制項
一、WebBrowser控制項(通過Style的設定可以實現部分列印)
<object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>
二、WebBrowder控制項的方法
1、列印  
WebBrowser1.ExecWB(6,1);
2、列印設定
 WebBrowser1.ExecWB(8,1);
3、預覽列印
 WebBrowser1.ExecWB(7,1);
 
 三、列印頁首頁尾設定
 var hkey_root,hkey_path,hkey_key
 hkey_root="HKEY_CURRENT_USER"
 hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"
 1、清空頁首頁尾
 
 try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
}catch(e){}
 2、設定頁首頁尾 www.2cto.com
 
 try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b頁碼,&p/&P")
hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d")
}catch(e){}
四、頁面列印
由於列印是會把整個頁面都列印出來的,但如果只需要列印資料表格,這時我們就把不想列印的部份隱藏起來
1、
//把指定id以外的層統統隱藏
function setdivhidden(id){
    var divs=document.getElementsByTagName("DIV");
    for(var i=0;i<divs.length;i++)
    {
        if(divs.item(i).id!=id)
            divs.item(i).style.display="none";
    }
}
2、
 // 列印版面設定
function printsetup(){
    WebBrowser.execwb(8,1);           
}
3、// 列印頁面預覽
function printpreview(){
  WebBrowser.execwb(7,1);           
}
4、列印
function printit() {
  if (confirm('確定列印嗎?'))
  WebBrowser.execwb(6,1)
}
 
5、HTML頁面元素
 <OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
 <input type=button name=button_print value="列印" class="noprint" onclick="javascript:printit()">
 <input type=button name=button_setup value=”列印版面設定” class="noprint" onclick="javascript:printsetup();">
 <input type=button name=button_show value="預覽列印" class="noprint" onclick="javascript:printpreview();">

摘自Core_Star的專欄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.