웹 브라우저 인쇄 미리 보기

7633 단어 browser
<script type="text/javascript">

    //    

    function PrintGrid(ElementId, PageTitle) {

        var ReportContent = "";

        var PrintWindow = window.open("", "mywindow", "menubar=1,status=1,scrollbars=1,width=800,height=500");



        ReportContent += "<html>";

        ReportContent += "<head>";

        ReportContent += "<title>";

        ReportContent += PageTitle;

        ReportContent += "</title>";

        ReportContent += "<style type='text/css'>";

        ReportContent += "<link rel='stylesheet' type='text/css' href='http://www.cnblogs.com/Content/css/right.css'/>";





        ReportContent += "body { font-family: Arial 12px; margin: 0px; width: 100%; }";

        ReportContent += ".print-header { width: 100%; border: solid 1px Black; text-align:center; vertical-align: middle; margin: 5px 0px 5px 0px; line-height: normal; font-size:14px; background-color: #cbcbcb; }";

        ReportContent += ".tablestyle { font-family: Arial; font-size: small; border: solid 1px #8C8C8C; font-size: 12px;}";

        ReportContent += ".headerstyle th { border-color: #ABABAB; border-style: solid solid solid none; border-width: 1px 1px 1px medium; text-align:left; font-weight: normal; vertical-align: bottom; background-color: #ececec; padding: 2px 0px 0px 4px; font-family: Arial; font-size: 12px; vertical-align: top;}";

        ReportContent += ".rowstyle td { border-color: #ABABAB; border-style: solid solid solid none; border-width: 1px 1px 1px medium; text-align:left; padding: 2px 0px 0px 4px; font-family: Arial; font-size: 12px; vertical-align: top; }";

        ReportContent += ".altrowstyle td { border-color: #ABABAB; border-style: solid solid solid none; border-width: 1px 1px 1px medium; text-align:left; padding: 2px 0px 0px 4px; font-family: Arial; font-size: 12px; vertical-align: top; }";

        ReportContent += ".PrintVisibleCol { display: block; }";

        ReportContent += ".PrintInvisibleCol { display: none; }";

        // Added H1 and H2 for printing the checklist data item grading page.

        ReportContent += "H1 { text-align:left; font-size: 14px; font-weight:normal; font-weight: bold;}";

        ReportContent += "H2 { text-align:left; font-size: 14px; font-weight:normal; font-weight: bold;}";



        ReportContent += "</style>";

        ReportContent += "</head>";



        ReportContent += "<body onload='window.print();'>";

        //ReportContent += "<body>";



        ReportContent += "<div style='text-align: left; margin: 5px 0px 2px 2px;'><img src='/images/logo.gif' border='0'></div>";



        ReportContent += "<table cellspacing='0' cellpadding='0' width='100%' class='print-header'>";

        ReportContent += "<tr>";

        ReportContent += "<td style='padding: 5px 0px 5px 0px;' align='center'>" + PageTitle.toUpperCase() + "</td>";

        ReportContent += "</tr>";

        ReportContent += "</table>";



        ReportContent += " <table cellspacing='0' cellpadding='0' width='100%' class='print-grid-content'>";

        ReportContent += "<tr>";

        ReportContent += "<td valign='top'>";



        if (document.getElementById(ElementId) != null) {

            var eles = $("#" + ElementId).find("input:checked");

            if (eles.length > 0) {

                eles.each(function () {

                    ReportContent += "<tr align='center'>" + $(this).closest("tr").html() + "</tr>";

                });

            }

            else {

                ReportContent += $("#" + ElementId).html();

            }

        }



        ReportContent += "</td>";

        ReportContent += "</tr>";

        ReportContent += "</table> ";



        var dteNow = new Date();

        ReportContent += "<div style='padding: 10px 0px 10px 2px; font-family: Arial; font-size: 9px; text-align: center;'>Copyright &copy; " + dteNow.getFullYear() + "   Inc. All rights reserved.</div>";



        ReportContent += "</body>";

        ReportContent += "</html>";





        PrintWindow.document.write(ReportContent);

        PrintWindow.print();

        PrintWindow.document.close();

        return false;

        //PrintWindow.focus();

    };

</script>

주: 이상은 간단한 예로 사용할 때 구체적인 수요에 따라 양식을 조정합니다.

좋은 웹페이지 즐겨찾기