网页打印总结(2)

   有时候需要根据自己的要求打印网页,此时就不能直接利用浏览器的打印了,要用JavaScript控制打印网页的内容,具体实现如下:

function PrintTest(){

    var history = document.body.innerHTML;
    document.body.innerHTML = document.getElementById(“Test”).innerHTML;
    window.print();
    document.body.innerHTML = history;
    window.location.reload();

}

 

<button onclick="PrintTest()"></button>
<div id="Test">

//打印内容

</div>

 

posted @ 2013-02-01 12:19  绿茶叶  阅读(260)  评论(0编辑  收藏  举报