如何使用Javascript打印HTML页面 [英] How to print HTML page using Javascript
本文介绍了如何使用Javascript打印HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Javascript中定义了一个打印功能,我将从HTML页面获取ID,并将特定HTML标签的innerHTML添加到打印文档中。但对于某些ID,内容会添加两次,尽管我只调用了一次ID。如何解决这个问题?
I have defined a Print Function in Javascript where I will get "IDs" from the HTML page and add the innerHTML of the particular HTML Tag to the printing document. But for certain IDs the content is adding twice eventhough I am calling the ID once. How to resolve this?
function Print()
{
var strContent = "<html><head></head><body>";
var idHTMLTag = document.getElementById('myTable');
var WinPrint = window.open('', '', 'letf=400px,top=100px,width=800px,height=500px,toolbar=0,scrollbars=1,status=0,');
if(get_tags[i].id == 'myTable')
{
strContent = strContent + idHTMLTag.innerHTML;
}
strContent = strContent + "</body></html>";
WinPrint.document.write(strContent);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
}
ID为'myTable'的HTML标记在WinPrint文档中重复两次。请帮我解决这个问题。
the HTML tag with ID 'myTable' is repeating twice in the "WinPrint" document. Please help me to resolve the issue.
推荐答案
这篇关于如何使用Javascript打印HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文