尝试在新窗口中打印内容 [英] trying to print the contents in a new window

查看:113
本文介绍了尝试在新窗口中打印内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将打印 html 内容添加到新的窗口

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();

我正在获取空白窗口没有 html 内容呢?

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

推荐答案

尝试设置新的窗口名称引用,删除 $()包装 w .focus() .print() .close() as jQuery()没有方法 .print()调用 .print()链接到 $()将返回 TypeError:undefined不是函数

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/

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

这篇关于尝试在新窗口中打印内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆