gpt4 book ai didi

javascript - 使用javascript打印html弹出窗口

转载 作者:行者123 更新时间:2023-11-28 00:08:16 25 4
gpt4 key购买 nike

如何打印在弹出窗口中打开的 html 页面?

我试过的是:

function printFile() {
var w = window.open('test.htm', 'name', 'width=200,height=200');
w.focus();
w.print();
}

但是上面的代码总是打印 about:blank。

最佳答案

您必须等待窗口加载:

function printFile() {
var w = window.open('test.htm', 'name', 'width=200,height=200');
w.onload = w.print;
w.focus();
}

关于javascript - 使用javascript打印html弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17122773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com