尝试在新 window 中打印内容

trying to print the contents in a new window

我正在尝试 print html contents 到新的 window

var w= window.open();
var htmlContent = $(printdiv).html(printcontent);
$(w.document.body).html(htmlContent);
$(w).location.reload();
$(w).focus();
$(w).print();
$(w).close();

我得到的是 blank window 而没有 html 内容?

尝试设置新的 window 名称引用,删除 $() 包装 w at .focus() , .print() , .close() as jQuery() 没有方法 .print() 调用 .print() 链接到 $() 会 return TypeError: undefined is not a function

// set `w` name reference
var w = window.open("", "w");
var htmlContent = $(printdiv).html(printcontent);
$(w.document.body).html(htmlContent);
// $(w).location.reload();
w.focus();
w.print();
w.close();

jsfiddle http://jsfiddle.net/14f5owux/