[英]IE7 & IE8 javascript print function
I'm having a javascript issue I can't figure out. 我遇到了无法解决的JavaScript问题。 I've taken a snippet of code that I got here and am using it in this page.
我已经采取的代码,我有一个片段在这里 ,并在使用它我这个页面。
The idea is that users can click the 'Print List' button and the listing is copied to a div within a hidden iframe and printed. 这个想法是,用户可以单击“打印列表”按钮,然后将列表复制到隐藏的iframe中的div并进行打印。 The printed page contains the the iframe source HTML with the list inserted properly.
打印的页面包含iframe源HTML以及正确插入的列表。 However, in IE7 & 8, the printed page is the full parent page, not the iframe.
但是,在IE7和8中,打印页面是完整的父页面,而不是iframe。 The behavior in IE9, Chrome and FF is correct.
IE9,Chrome和FF中的行为是正确的。
I tried debugging the script but I couldn't see where it was going wrong. 我尝试调试该脚本,但是看不到哪里出错了。
Here's the code that the Print List click triggers: 这是“打印列表”单击触发的代码:
function printSection(id) {
if (document.getElementById('print_frame').contentDocument){
theIframe = document.getElementById('print_frame').contentDocument;
}
else {
theIframe = document.frames['print_frame'].document;
}
var thePrinter = theIframe.getElementById('print_section');
var theCopy = document.getElementById(id);
thePrinter.innerHTML = theCopy.innerHTML;
parent.print_frame.printPage();
}
And here's the printPage() function: 这是printPage()函数:
function printPage() {
window.parent.print_frame.focus();
window.print();
}
I'd appreciate any help. 我将不胜感激。 Please let me know if you need more information.
如果您需要更多信息,请告诉我。 Thanks so much.
非常感谢。
A simpler solution might just be to use CSS media types to hide the content of the page and show an otherwise hidden element for print. 一个更简单的解决方案可能只是使用CSS媒体类型来隐藏页面的内容,并显示其他隐藏的元素以供打印。
CSS 的CSS
.print{display:none;}
@media print {
.pagecontainer{display:none;}
.print{display:block;}
}
HTML 的HTML
<body>
<div class="pagecontainer">
Page content here
</div>
<div class="print">Only show this when printing</div>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.