【问题标题】:Print the page as it is in AngularJS在 AngularJS 中打印页面
【发布时间】:2016-09-17 10:25:27
【问题描述】:

我尝试使用https://github.com/gilf/ngPrint 指令进行打印。我可以打印页面,但打印时页面设计完全折叠。有没有办法按原样打印页面? 注意:我正在为页面使用 Angular Material

【问题讨论】:

    标签: javascript angularjs angular-material


    【解决方案1】:

    你可以试试下面的代码:

    function printPage() {
      var contentToPrint = document.getElementById('#myDiv').innerHTML;
      var windowPopup = window.open('', '_blank', 'width=500,height=500');
      windowPopup.document.open();
      windowPopup.document.write('<html><head><link rel="stylesheet" type="text/css" href="" /></head><body onload="window.print()">' + contentToPrint + '</body></html>');
      windowPopup.document.close();
    } 
    

    【讨论】:

    • 用这个例子也许他会遇到同样的问题,必须添加他的css样式和媒体的引用,像这样:&lt;head&gt;&lt;link rel="stylesheet" type="text/css" href="styles/main.css" type=\"text/css\" media=\"print\" /&gt;&lt;/head&gt;
    猜你喜欢
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多