admin管理员组

文章数量:1431037

I have a div of a gridview that needs to be printed. I am using a CallPrint JavaScript method to print the div. I need to add a header and also re-size the div to fit the page better. Here is the CallPrint method.

    function CallPrint(strid) {
        var prtContent = document.getElementById(strid);
        var WinPrint =
        window.open('', '', 'letf=0,top=0,width=800,height=550,toolbar=0,scrollbars=0,status=0');
        WinPrint.document.write(prtContent.innerHTML);
        WinPrint.document.close();
        WinPrint.focus();
        WinPrint.print();
        WinPrint.close();
        prtContent.innerHTML = strOldOne;
    }    //Generating Pop-up Print Preview page    

I have a div of a gridview that needs to be printed. I am using a CallPrint JavaScript method to print the div. I need to add a header and also re-size the div to fit the page better. Here is the CallPrint method.

    function CallPrint(strid) {
        var prtContent = document.getElementById(strid);
        var WinPrint =
        window.open('', '', 'letf=0,top=0,width=800,height=550,toolbar=0,scrollbars=0,status=0');
        WinPrint.document.write(prtContent.innerHTML);
        WinPrint.document.close();
        WinPrint.focus();
        WinPrint.print();
        WinPrint.close();
        prtContent.innerHTML = strOldOne;
    }    //Generating Pop-up Print Preview page    
Share Improve this question asked Sep 2, 2011 at 15:36 Lucas Lucas 1251 gold badge2 silver badges11 bronze badges 3
  • You don't ask any questions here. – GAgnew Commented Sep 2, 2011 at 15:40
  • 1 Instead of js why don't you write a dedicated CSS file for media="print"? (take a look here: alistapart./articles/goingtoprint) – daveoncode Commented Sep 2, 2011 at 15:42
  • This was helpful...it made it much easier to print and style how the page should look! Thanks! – Lucas Commented Sep 2, 2011 at 20:53
Add a ment  | 

1 Answer 1

Reset to default 4

This is not the way to go.

Instead you should have something like <link rel="stylesheet" type="text/css" media="print" href="print.css" /> at the top of your html file, and change that element by providing cutom CSS for the print.

Here for more reading : http://www.alistapart./articles/goingtoprint/

本文标签: javascriptResize a div when printingStack Overflow