首页 > 解决方案 > 打印选项打不开

问题描述

我在带有 JS 的 google 脚本中有一个 html 文件,尝试使用以下代码进行打印。它打开没有打印选项的文档,我仍然需要执行 cmd+P 才能打印。请问有什么想法吗?

function printBadge() {
        var attendee = document.getElementById("info").value; 
        var fullName = "xxx";
        var snb = "xxx";
        var printFonts = "fonts";
        var printStyle = "style";
        var printArea = "badge info";

          w = window.open();
          w.document.write(printFonts + printStyle + printArea).html();
          w.document.close();
          w.focus();
          w.print();
          w.close();
         return false;
      }

标签: javascripthtmlgoogle-apps-scriptgoogle-sheetsprinting

解决方案


原因就是这条线w.document.write(printFonts + printStyle + printArea).html();。没有.html()关联的功能document.write,当您尝试执行它时,它在那里失败,因此窗口卡住了。

它需要w.document.write(printFonts + printStyle + printArea)没有 .html() 功能。

希望能帮助到你。如有任何疑问,请回复。


推荐阅读