我希望通過傳遞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