trying to print the contents in a new window

久未见 提交于 2019-12-13 03:37:49

问题


I am trying to print the html contents to a new window.

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

I am a getting a blank window with no html contents instead?


回答1:


Try setting new window name reference , removing $() wrapper around w at .focus() , .print() , .close() as jQuery() does not have method .print() calling .print() chained to $() would 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/



来源:https://stackoverflow.com/questions/31210555/trying-to-print-the-contents-in-a-new-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!