无法使用JavaScript打印功能打印图像

cant print images with JavaScript print function

本文关键字:打印 功能 图像 JavaScript      更新时间:2023-09-26

我正在尝试打印一份包含文本和图像的报告。我正在使用一个javascript函数来调用打印功能。除了页面上的图像没有显示在新的打印窗口中之外,其他一切都很好。我已经包含了所有的CSS文件,但我的图像仍然没有出现在新的打印窗口中。即使我不包括CSS链接,它也是一样的。

我要打印的javascript函数是:

function printfun(){
        var disp_setting = "toolbar=no,location=no,directories=no,menubar=no,";
        disp_setting += "scrollbars=no,left=0,top=0,resizable=yes,width=900 height=650,modal=yes,";
        var content_vlue = document.getElementById('<%= tblCharts.ClientID %>').innerHTML;   
        var docprint = window.open("", "", disp_setting);
        docprint.document.write('<html><head>');
        docprint.document.write('</head>');
        docprint.document.write('<body onLoad="self.print()">');
        docprint.document.title = "";
        docprint.document.write('<link href="../style/design.css" rel="Stylesheet" type="text/css" />');
        docprint.document.write('<link href="../App_Themes/style/graphs.css" rel="Stylesheet" type="text/css" />');
        docprint.document.write(content_vlue);
        docprint.document.write(tblCharts);        
        docprint.document.write("</body></html>");
        docprint.document.close();
        docprint.focus();
}

这些图像是CSS中的背景图像吗?如果是这样,浏览器可能不会默认设置为打印这些内容。这就是用户必须更改的浏览器设置。