尝试在新窗口中打印内容

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

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

我是一个没有html内容的blank window

尝试设置新window名称引用,删除围绕w .focus() $()包装,因为jQuery()没有方法.print()调用.print()链接到$()会返回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/