可能重复:
Jquery:如何检查新打开的窗口是否已完全加载?/window 加载外部页面(如 www.yahoo.com)
所以我有这个功能,它需要一些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();
}
谢谢