實現網頁列印幾種方法

來源:互聯網
上載者:User

如果要列印的只是整個頁面中的一小部分,就最好採用第二種方法。

第一種方法:如果要列印的頁面排版和原web頁面相差很大,採用此種方法。

點列印按鈕彈出新視窗,把需要列印的內容顯示到新視窗中,在新視窗中調用window.print()方法,然後自動關閉新視窗。


指定列印範圍

把要列印的內容放入一個 span或div,然後通過一個函數列印。

<span id='div1'>把要列印的內容放這裡</span>
<p>所有內容</p>

<div id="div2">div2的內容</div>
<a href="javascrīpt:printme()" target="_self">列印</a>

<scrīpt language="javascrīpt">
function printme()
{
document.body.innerhtml=document.getelementbyid('div1').innerhtml+'<br/>'+document.getelementbyid('div2').innerhtml;
window.print();
}
</scrīpt>

方法二

用css教程式控制制

 

引用:@media print
.a {display:block}
.b {display:hidden}
把你不想列印的部分class設為b
首先在網頁中添加:
     

引用:<object id="webbrowser" height="0" width="0" classid="clsid:8856f961-340a-11d0-a96b-00c04fd705a2"
      viewastext>

 

<style media=print type="text/css">
.noprint{visibility:hidden}
</style>
要列印的內容。哈哈!
<p class="noprint">將不列印的代碼放在這裡。</p>
<a href="javascrīpt:window.print()" target="_self">列印</a>

方法三 用ie列印網頁

    internet explorer(簡稱ie)5.0以上版本強大的列印及預覽列印功能。本文就向大家介紹如何用ie來列印網頁。(誰?誰?誰在扔西紅柿?下面一片噓聲:這還用得著你講呀?!)咳咳咳,是的是的,在ie中列印網頁實在是太簡單不過了。只需點一下工具列上“列印”按鈕就可將當前網頁列印出來


方法四

xml/html代碼

<a href="網頁特效:;" onclick="doprint()">列印</a>

引用:
<script language="javascript">
var hkey_root,hkey_path,hkey_key
hkey_root="hkey_current_user"
hkey_path="softwaremicrosoftinternet explorerpagesetup"
//設定網頁列印的頁首頁尾為空白
function pagesetup_null(){
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){}
}
//設定網頁列印的頁首頁尾為預設值
function pagesetup_default(){
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){}
}
</script>
<input type="button" value="清空頁碼" onclick=pagesetup_null()>
<input type="button" value="恢複頁碼" onclick=pagesetup_default()>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.