HTML調用瀏覽器打印機方法


<!DOCTYPE html>  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>局部打印案例</title>  
<script type="text/javascript">     
    function doPrint() {      
        bdhtml=window.document.body.innerHTML;      
        sprnstr="<!--startprint-->";      
        eprnstr="<!--endprint-->";      
        prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);      
        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));      
        window.document.body.innerHTML=prnhtml;   
        window.print();      
     location.reload(); }
</script> </head> <body> <p>1不需要打印的地方</p> <p>2這里不要打印啊</p> <!--startprint--><!--注意要加上html里star和end的這兩個標記--> <h1>打印標題</h1> <p>打印內容</p> <!--endprint--> <button type="button" onclick="doPrint()">打印</button> <p>不打印的地方啊哈哈哈哈</p>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM