由于Windows Chrome中的打印功能导致站点故障

时间:2014-07-15 11:20:56

标签: javascript jquery windows google-chrome

我正在建立一个有图库的网站,点击每张图片后我们会显示更大的图片。

我们还可以选择在Facebook上分享并打印。

通过调用浏览器打印功能来完成打印功能:

$("#print").on(isMobile.any() ? 'touchend' : 'click', function (e) {

    var printWindow = window.open('', 'Print Window', 'height=400,width=700');
    printWindow.document.write('<html><head><title>Print Window</title>');
    printWindow.document.write('</head><body ><img src=\'');
    printWindow.document.write($(".large-img").attr("src"));
    printWindow.document.write('\' /></body></html>');
    printWindow.document.close();
    printWindow.print();

});

关闭打印窗口后,图像停止加载(单击下一个按钮)。

Windows Chrome打印功能是否存在任何已知问题?

链接:已删除链接

注意:该网站在Ubuntu的Windows Firefox,IE,Chrome上正常运行。

1 个答案:

答案 0 :(得分:1)

不幸的是,它似乎是一个Chrome错误:

https://code.google.com/p/chromium/issues/detail?id=363392 https://code.google.com/p/chromium/issues/detail?id=359627

我建议您使用css打印样式表而不是打开弹出窗口,例如:

@media print{
    body{
        background:#ffffff;
    }
    .header, .gallety-content, .close-btn, .control-nav, .footer, .bottom-line{
        display:none;
    }
    .middle-content{
        background:none;
    }

    .gallery-overlay{
        left:0;
        top:0;
        position:relative;
    }

    .glry-large-img{
        left:0;
        top:0;
        position:relative;
        margin:0 auto;
        width:100%;
    }

}

希望有所帮助

相关问题