【发布时间】:2012-12-03 18:21:34
【问题描述】:
所以我有这个功能,它需要一些html代码,它会打开一个新窗口并将代码放在窗口中,然后提示打印功能。但是,有时,打印 css 没有被加载,并且打印没有构建正确的页面。有什么方法可以查看新打开的窗口是否加载了所有内容?
function printer(el)
{
print_window= window.open();
var print_css = '<link rel="stylesheet" href="css/bootstrap.css" type="text/css" />';
print_css = print_css + '<link rel="stylesheet" href="css/main.css" type="text/css" />';
print_css = print_css + '<link rel="stylesheet" href="css/print.css" type="text/css" media="print" />';
print_window.document.write("<html><head>" + print_css + "</head><body>" + "<div class='contents'>" + el + "</div>" + "</body> </html>");
print_window.document.close();
print_window.focus();
print_window.print();
print_window.close();
}
谢谢
【问题讨论】:
-
print_window.onload工作吗? -
顺便说一句,我在您的代码中没有看到 jQuery。您的意思是将其添加为标签吗?
-
print_window.onload 确实有效,但由于某种原因,它不能很好地与打印功能一起使用。当我尝试发出警报时,它可以工作,但是对于打印,新打开的窗口只是停留在那里,没有任何提示。
-
对不起,我以为 jQuery 会有解决方案,所以我标记了 jQuery。
标签: javascript html