我希望通过传递custome html代码来打印文档。通过javascript打印html/jquery
非工作代码,我已经写了:
function Clickheretoprint()
{
var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
disp_setting+="scrollbars=yes,width=780, height=780, left=100, top=25";
var content_vlue = document.getElementById("result_tbl").innerHTML;
var docprint=window.open("","",disp_setting);
docprint.document.open();
docprint.document.write('<html><head><title>Ashley Mattresses</title>');
docprint.document.write('</head><body onLoad="self.print()"><center>');
docprint.document.write('<TABLE width="100%" cellpadding=10 align=center valign="top"><TR valign="top"><TD width = "33%" valign="top">col1</TD><TD width = "33%" valign="top">col2</TD><TD width = "33%" valign="top">col3</TD></TR></TABLE>');
docprint.document.write('</center></body></html>');
docprint.document.close();
docprint.focus();
docprint.close();
}
这是我叫一个锚标记的HREF的方法,但没有得到所做的工作:
<a href="javascript:Clickheretoprint()">
我作为JavaScript/jQuery编码的新宠儿,请帮助我实现这一目标(通过纠正这一问题或提出一种方法),作为其迫切要求。
在此先感谢。
OH NO迫切?什么不起作用?控制台中是否有错误?你知道可以在没有新窗口的情况下只在页面上打印某些东西。看看CSS打印介质。 – epascarello 2012-03-19 12:22:12
@epascarello ya我重新检查了一点修改,发现在Firefox中工作,而不是在谷歌浏览器。早些时候我正在测试Chrome本身,所以无法打印。但也需要使用Chrome浏览器,请问您可以提出一些建议吗? 此外,感谢您对CSS打印介质的建议,它非常好,并且肯定会要求此功能。 – HarsH1610 2012-03-19 13:33:22
答案#2是正确的,但您必须添加:var disp_setting =“menubar = no; status = no; toolbar = no;”;或您选择的设置 – 2013-02-12 21:20:55