仅打印隐藏对象标签的内容 [英] Print ONLY the contents of a hidden object tag
问题描述
请考虑以下代码示例:
Consider the following code example:
<!DOCTYPE html>
<html>
<head>
<title>HTML5-Template</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
.print_this{
display: none;
}
@media print {
.print_this {
display: block;
width: 1024px;
height: 768px;
}
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function () {
setTimeout(function () {
var el = document.getElementById("report");
el.focus();
el.print();
}, 1500);
});
</script>
</head>
<body>
<div id="Container">
<object class="print_this" id="report" name="report" type="application/pdf" data="Certificate.pdf"></object>
</div>
</body>
</html>
我想在窗口中隐藏用户的对象,但只打印标签的内容当打印对话框显示时...这是可能的吗?
I want to hide the object from the user in the window, but print ONLY the contents of the tag when the print dialog is displayed...is this possible?
注意:代码来自互联网上的其他地方,但我有一种感觉,这是非常非标准的基于?
NOTE: Code was from elsewhere on the internet, however I have a feeling this is very much, non standards based?
推荐答案
你在正确的轨道上。现在,您需要在打印介质块中定义一个仅限屏幕的类( .screen_only {display:none;}
)以隐藏不想要的内容显示给打印机:
You're on the right track. Now you need to define, within the print media block, a screen-only class (.screen_only { display: none; }
) to hide the stuff you don't want to show to the printer:
.print_this{
display: none;
}
@media print {
.print_this {
display: block;
width: 1024px;
height: 768px;
}
.screen_only {
display: none;
}
}
请参阅 http://fiddle.jshell.net/jhfrench/UdQSX/2/show/ 为一个工作示例。当页面加载到浏览器中时,您会看到打印时不显示。现在打印页面,你会看到这只显示打印机。
See http://fiddle.jshell.net/jhfrench/UdQSX/2/show/ for a working example. When the page loads in a browser you will see "This doesn't show when printed". Now print the page and you will see "This only shows for the printer".
这篇关于仅打印隐藏对象标签的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!