javascript - 打印选项打不开
问题描述
我在带有 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;
}
解决方案
原因就是这条线w.document.write(printFonts + printStyle + printArea).html();
。没有.html()
关联的功能document.write
,当您尝试执行它时,它在那里失败,因此窗口卡住了。
它需要w.document.write(printFonts + printStyle + printArea)
没有 .html() 功能。
希望能帮助到你。如有任何疑问,请回复。
推荐阅读
- msbuild - 如何仅在运行增量执行目标时添加项目?
- html - 如何在html列表中的文本后面放置一个箭头?
- vba - 如何在访问表单和报告标题中使用表格中的附件图像?
- rbenv - rbenv 安装 2.6.3 构建失败
- java - Apache beam WithTimestamps:输出时间戳不得早于当前输入的时间戳
- ipython - 如何从笔记本中的javascript查询ipython(jupyterlab?)内核?
- android - React Native Onesignal OnPressed 通知在发布版本中不起作用
- c# - 父面板的 MouseWheel - 从子传递事件
- python - Pandas 使用 item() 从日期时间索引中给出整数
- c# - 无法在与枚举绑定的组合框中设置“SelectedValue”