如果代码是纯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文件和手写的一样,但是就是不能分页,好奇怪的问题。
大家可以写段简单的ASP/PHP代码测试一下,让PHP循环生成上面的内容,即使看HTML代码完全一样,也不会分页,如果在代码中不能分页打印,那么就没有任何意义了,因为很多数据都是从数据库中读取然后由程序生成的~~~~~~~~~~~我在PHP板块发了同样的帖子,他们建议换个打印控件
用其他控件不失为一个解决方法,但是出现这种情况到底是怎么回事呢?非常奇怪的问题,希望大家研究一下
<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文件和手写的一样,但是就是不能分页,好奇怪的问题。
大家可以写段简单的ASP/PHP代码测试一下,让PHP循环生成上面的内容,即使看HTML代码完全一样,也不会分页,如果在代码中不能分页打印,那么就没有任何意义了,因为很多数据都是从数据库中读取然后由程序生成的~~~~~~~~~~~我在PHP板块发了同样的帖子,他们建议换个打印控件
用其他控件不失为一个解决方法,但是出现这种情况到底是怎么回事呢?非常奇怪的问题,希望大家研究一下
不过在 iframe 中似乎不行