如果代码是纯HTML的,如:<html>
<title>JS 分页批量打印解决方案(只支持IE)</title>
<script language="javascript">
function printWithAlert() {
document.all.WebBrowser.ExecWB(6,1);
}
function printWithoutAlert() {
PageSetup_Null();
document.all.WebBrowser.ExecWB(6,6);
}
function printSetup() {
document.all.WebBrowser.ExecWB(8,1);
}
function printPrieview() {
document.all.WebBrowser.ExecWB(7,1);
}
function printImmediately() {
document.all.WebBrowser.ExecWB(6,6);
window.close();
}
</script>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 style="display:none">
</OBJECT>
</noscript>
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style><table align="center" class=NOPRINT>
<tr>
<td align="center"><BUTTON title=打印 onclick=printWithAlert()>打印</BUTTON>
<BUTTON title=直接打印 onclick=printWithoutAlert()>直接打印</BUTTON>
<input type=button value="打印设置" onClick="printSetup()" >
<button onclick ='printPrieview()' title='打印预览...' >打印预览</button></td>
</tr>
</table>
<div class=NOPRINT> 以下为打印区:<br>
</div>
<hr size=1 noshadow color=black class=NOPRINT >
<table class="PageNext" >
<tr>
<td colspan=2><h1>
第一页的内容
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 </h1>
</td>
</tr>
</table>
<hr size=1 noshadow color=black class=NOPRINT >
<div class="PageNext"><h1>
第二页内容
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222</h1>
</div>
<hr size=1 noshadow color=black class=NOPRINT ><h1>
第三页内容</h1>
</html>
这样可以看到能够正确分页但是如果内容是PHP动态生成的,打印预览是不会分页的,但是右键查看源代码,生成的HTML文件和手写的一样,但是就是不能分页,好奇怪的问题。
大家可以写段简单的PHP代码测试一下,让PHP循环生成上面的内容,即使看HTML代码完全一样,也不会分页,如果在代码中不能分页打印,那么就没有任何意义了,因为很多数据都是从数据库中读取然后由程序生成的~~~~~~~~~~~希望知道如何解决这个问题的前辈指点,谢谢。晕了两天了,搞不懂怎么回事
<title>JS 分页批量打印解决方案(只支持IE)</title>
<script language="javascript">
function printWithAlert() {
document.all.WebBrowser.ExecWB(6,1);
}
function printWithoutAlert() {
PageSetup_Null();
document.all.WebBrowser.ExecWB(6,6);
}
function printSetup() {
document.all.WebBrowser.ExecWB(8,1);
}
function printPrieview() {
document.all.WebBrowser.ExecWB(7,1);
}
function printImmediately() {
document.all.WebBrowser.ExecWB(6,6);
window.close();
}
</script>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 style="display:none">
</OBJECT>
</noscript>
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style><table align="center" class=NOPRINT>
<tr>
<td align="center"><BUTTON title=打印 onclick=printWithAlert()>打印</BUTTON>
<BUTTON title=直接打印 onclick=printWithoutAlert()>直接打印</BUTTON>
<input type=button value="打印设置" onClick="printSetup()" >
<button onclick ='printPrieview()' title='打印预览...' >打印预览</button></td>
</tr>
</table>
<div class=NOPRINT> 以下为打印区:<br>
</div>
<hr size=1 noshadow color=black class=NOPRINT >
<table class="PageNext" >
<tr>
<td colspan=2><h1>
第一页的内容
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 </h1>
</td>
</tr>
</table>
<hr size=1 noshadow color=black class=NOPRINT >
<div class="PageNext"><h1>
第二页内容
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222</h1>
</div>
<hr size=1 noshadow color=black class=NOPRINT ><h1>
第三页内容</h1>
</html>
这样可以看到能够正确分页但是如果内容是PHP动态生成的,打印预览是不会分页的,但是右键查看源代码,生成的HTML文件和手写的一样,但是就是不能分页,好奇怪的问题。
大家可以写段简单的PHP代码测试一下,让PHP循环生成上面的内容,即使看HTML代码完全一样,也不会分页,如果在代码中不能分页打印,那么就没有任何意义了,因为很多数据都是从数据库中读取然后由程序生成的~~~~~~~~~~~希望知道如何解决这个问题的前辈指点,谢谢。晕了两天了,搞不懂怎么回事
解决方案 »
- 求一段URL转发php代码
- 急聘:上海闵行紫竹园招聘C++/PHP
- 帮忙解释一下这个$arrayid[$i]前后都加点,还有这个引号也看不懂
- php下fckedit图片在本地好使,放到服务器上好使?
- zend studio workspace问题[求助]
- 添加表单中的option成功后,在IE中的查看源代码看不到option的选项吗?
- 关于安装zendstudio-5.5.1 出现的错误信息 Javaw.exe没有找到
- php提交给form怎么就取不到值?请教
- php怎样把数据库数据循环绑定到一个八行四列的表格里面去呢,知道的老师请说一下思路,谢谢
- phpmail发送嵌入式图片的问题
- 权限管理系统
- 怎样弄
好负责的版主!
套马杆的汉子你威武雄壮!测试了一下,发现问题根源了:
如果是php代码生成的:<html>
<head>
<title>web打印</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="print">
.noprint{display:none;}
.pagenext{page-break-after:always;}
</style>
<script language="javascript">
function printWithAlert() {
document.all.WebBrowser.ExecWB(6,1);
}
function printWithoutAlert() {
PageSetup_Null();
document.all.WebBrowser.ExecWB(6,6);
}
function printSetup() {
document.all.WebBrowser.ExecWB(8,1);
}
function printPrieview() {
//PageSetup_Null();
document.all.WebBrowser.ExecWB(7,1);
}
function printImmediately() {
document.all.WebBrowser.ExecWB(6,6);
window.close();
}
</script>
</head>
<body>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 style="display:none"></OBJECT>
<!--浮动控制层:数据筛选和打印-->
<div id="floatctl" class="noprint">
<input type="button" value="打印预览" onclick="printPrieview();"/>
<input type="button" value="直接打印" onclick="window.print() ;" />
</div>
<br />
<br />
<?php
function gentable($pagenum)
{
echo '<table width="860" border="1" cellpadding="0" cellspacing="0" style="page-break-after: always">';
echo '<tr><td align="center"><h1>WEB分页打印 </h1></td></tr><tr><td>';
echo '<table width="100%" class="tab1"><tr><td>这是第'.$pagenum.'页</td></tr>';
echo '</table>';
echo '</td></tr></table>';
}
for($i=0;$i<10;$i++)
{
gentable($i+1);
}
?>
</body>
</html>确实没有问题,但是如果一个页面iframe src=这个页面,就不能正确分页:<html>
<head>
<title>测试iframe分页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="images/style.css" type="text/css" rel="stylesheet">
<style type="text/css" media="print">
.noprint{display:none;}
.print{display:block;}
.pagenext{page-break-after: always;}
</style>
</head><body>
<!--这个test.php就是上面的代码-->
<iframe src="test.php" width="100%" height="100%"></iframe>
</body>
</html>如果这样,就不能正确分页了
这也算解决问题了,但是请问这是怎么回事呢?是控件的问题吗?
http://bbs.csdn.net/topics/390443315
这也是我的帖子,版主请回复一下,把分给你