0

我正在打印一个包含在面板中的 asp.net 中的 gridview - 它在 IE 中完美运行

  1. 在 Opera 12.02 中,它似乎打印出我的主表单而不是打印页面?你知道这是为什么吗?
  2. 在 Mozilla firefox 16.0.2 中,它只在打印预览中加载一页并打印那一页?你知道这是为什么吗?

我假设问题出在我的 javascript 中 - 如果需要,我可以发布标记,但希望这不是必需的。

感谢达摩 javascript

<script type="text/javascript">
        function PrintGridData(GridToPrint, PanelName) {
            try {
                var Grid = document.getElementById(GridToPrint);
                var printContent = document.getElementById(PanelName);
                //alert(printContent);
                if (Grid)  // See if the Grid Exists First
                {

                    if (Grid.rows.length > 0) { // See if the Grid contains any rows
                        var windowUrl = 'about:blank';
                        var UserLoggedIn = $("#lblUser").text()
                        var now = new Date();
                        var strDateTime = [[AddZero(now.getDate()), AddZero(now.getMonth() + 1), now.getFullYear()].join("/"), [AddZero(now.getHours()), AddZero(now.getMinutes())].join(":"), now.getHours() >= 12 ? "PM" : "AM"].join(" ");
                        var Database = 'ProductionDatabase';
                        var windowName = 'Report';
                        var AuditPrintDetailEverypage =  UserLoggedIn + ' Time : ' + strDateTime ;
                        var AuditPrintDetailLastPage = '      System Report ' + ' Source Database: ';
                        var WinPrint = window.open(windowUrl, windowName, 'left=300,top=300,right=500,bottom=500,width=1000,height=500');
                        WinPrint.document.write('<' + 'html' + '><head><link href="assets/css/Print.css" rel="stylesheet" type="text/css" /><title>' + AuditPrintDetailEverypage + '</title> </head><' + 'body  style="background:none !important"' + '>');
                        WinPrint.document.write(printContent.innerHTML);
                        WinPrint.document.write('          ' + AuditPrintDetailLastPage);
                        WinPrint.document.write('<' + '/body' + '><' + '/html' + '>');
                        WinPrint.document.close();
                        //alert(printContent.innerHTML);
                        //alert(WinPrint.document);
                        if (window.opera) {
                        //alert('opera browser detected')
                           window.onload = window.print();
                            //window.onload = WinPrint.print();
                            //WinPrint.close();
                        }
                        else {

                            WinPrint.focus();
                            WinPrint.print();
                            WinPrint.close();
                        }
                    }
                    else { // No Results to print 
                        document.getElementById('lblErrorCode').innerHTML = '-1';
                        document.getElementById('lblErrorMessage').innerHTML = 'You have no Results to print. Please run a report.';
                        document.getElementById('lblExMessage').innerHTML = '-1';
                        var modal = $find("modalPopupExtenderError");
                        modal.show();
                    }
                }
                else { // No Grid to print 
                    document.getElementById('lblErrorCode').innerHTML = '-1';
                    document.getElementById('lblErrorMessage').innerHTML = 'You have no Grid to print. Please run a report.';
                    document.getElementById('lblExMessage').innerHTML = '-1';
                    var modal = $find("modalPopupExtenderError");
                    modal.show();
                    return;
                }

            }
            catch (err) {
                //alert(err);
                document.getElementById('lblErrorCode').innerHTML = '-1';
                document.getElementById('lblErrorMessage').innerHTML = err;
                document.getElementById('lblExMessage').innerHTML = '-1';
                var modal = $find("modalPopupExtenderError");
                modal.show();           
                return;
            }
        }
        function AddZero(num) {
            try {
                return (num >= 0 && num < 10) ? "0" + num : num + "";
            }
            catch (err) {
                //alert(err);
                document.getElementById('lblErrorCode').innerHTML = '-1';
                document.getElementById('lblErrorMessage').innerHTML = err;
                document.getElementById('lblExMessage').innerHTML = '-1';
                var modal = $find("modalPopupExtenderError");
                modal.show();
                return;
            }
        }
    </script>
4

1 回答 1

0

window.onload = window.print(); 应该是 window.onload = window.print; 我的CSS也溢出了:隐藏;哪个歌剧和 Mozilla 不喜欢所以我删除了这些

现在它工作正常,谢谢达摩

于 2012-10-31T21:18:16.573 回答