【问题标题】:Jquery/ Javascript Print issue with Internet explorer 11Internet Explorer 11 的 Jquery/Javascript 打印问题
【发布时间】:2014-09-10 15:48:41
【问题描述】:

当我使用 Internet Explorer 11 打印 HTML 元素(例如 div 或表格)时,我看不到打印预览。实际上打印过程根本没有开始。

我用这个 javascript 来打印。使用 Chrome 和 Firefox 可以正常工作

<script type="text/javascript">

function printData(){
var divToPrint=document.getElementById("tableId");
newWin= window.open("");
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
}


</script>

您能帮我解决这个问题吗?

谢谢大家

【问题讨论】:

    标签: jquery internet-explorer printing


    【解决方案1】:

    IE 对window.print() 方法有些奇怪。 我建议在 IE 中使用document.execCommand,如:

    function printData(){
        var divToPrint=document.getElementById("tableId");
        newWin= window.open("");
        newWin.document.write(divToPrint.outerHTML);
        if (!! navigator.userAgent.match(/Trident/gi)) {
            newWin.document.execCommand('print', false, null);
        } else {
            newWin.print();
        }
        newWin.close();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多