【发布时间】:2022-11-22 01:17:50
【问题描述】:
我在单击打开打印窗口的按钮时调用此函数,但我的页面内容也更改为 htmlData。我不想更改我的页面内容,而只想更改打开的打印窗口的内容。
任何解决方案?谢谢。
print() {
const WinPrint = window.open(
" ",
"_self",
"left=0,top=0,width=900,height=900,toolbar=0,scrollbars=0,status=0"
);
let htmlData =
"<html><head> <style....</html>";
WinPrint.document.write(htmlData);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
【问题讨论】:
-
那么,为什么要使用
"_self",作为上下文目标? "_self: the current browsing context." -
您是否了解过打印样式表,这样您就不必处理弹出窗口?
标签: javascript html jquery dom