天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

web 頁面分頁打印的實現

1.首先引入一個WebBrowser在需要打印的頁面,可以直接添加:
復制代碼 代碼如下:
<object id="WebBrowser" classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height="0" width="0">
</object>

到頁面,或者使用JavaScript在需要的時候臨時添加也可以:
復制代碼 代碼如下:
document.body.insertAdjacentHTML("beforeEnd",
"<object id=/"WebBrowser/" width=0 height=0 /
classid=/"clsid:8856F961-340A-11D0-A96B-00C04FD705A2/">");

2 .頁面設置和打印預覽
如下所示,直接調用即可
復制代碼 代碼如下:
document.all.WebBrowser.ExecWB(6,6) 直接打印
document.all.WebBrowser.ExecWB(8,1) 頁面設置
document.all.WebBrowser.ExecWB(7,1) 打印預覽

或者:
復制代碼 代碼如下:
execScript("document.all.WebBrowser.ExecWB 7, 1","VBScript");

3 隱藏不打印的頁面元素和分頁
CSS 有個Media 屬性,可以分開設置打印和顯示的格式。
如 <style media="print" type="text/css"> …</style> 中間的格式將只在打印時起作用,不會影響顯示界面。
所以可以設定
<style media="print" type="text/css">
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
然后給不想打印的頁面元素添加: class="Noprint" ,那就不會出現在打印和打印預覽中了。
想分頁的地方添加: <div class="PageNext"></div> 就可以了。
4.打印頁面的特定部分
通過將需要打印的特定部分另建一個頁面,然后裝入主頁面的一個IFrame中,再調用IFrame的打印方法,只打印IFrame中的內容實現的。
如:
<iframe style="visibility: visible" name="FrameId" width="100%" height="30%" src="NeedPrintedPage.ASP"></iframe>
下面的pringFrame js函數將只打印Iframe中的內容,可以直接引用使用,如printFrame(FrameId);
復制代碼 代碼如下:
window.print = printFrame;
// main stuff
function printFrame(frame, onfinish) {
if ( !frame ) frame = window;
function execOnFinish() {
switch ( typeof(onfinish) ) {
case "string": execScript(onfinish); break;
case "function": onfinish();
}
if ( focused && !focused.disabled ) focused.focus();
}
if (( frame.document.readyState !== "complete") &&( !frame.document.confirm("The document to print is not downloaded yet! Continue with printing?") ))
{
execOnFinish();
return;
}
var eventScope = printGetEventScope(frame);
var focused = document.activeElement;
window.printHelper = function() {
execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
printFireEvent(frame, eventScope, "onafterprint");
printWB.outerHTML = "";
execOnFinish();
window.printHelper = null;
}
document.body.insertAdjacentHTML("beforeEnd",
"<object id=/"printWB/" width=0 height=0 /
classid=/"clsid:8856F961-340A-11D0-A96B-00C04FD705A2/">");
printFireEvent(frame, eventScope, "onbeforeprint");
frame.focus();
window.printHelper = printHelper;
setTimeout("window.printHelper()", 0);
}
// helpers
function printIsNativeSupport() {
var agent = window.navigator.userAgent;
var i = agent.indexOf("MSIE ")+5;
return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}
function printFireEvent(frame, obj, name) {
var handler = obj[name];
switch ( typeof(handler) ) {
case "string": frame.execScript(handler); break;
case "function": handler();
}
}
function printGetEventScope(frame) {
var frameset = frame.document.all.tags("FRAMESET");
if ( frameset.length ) return frameset[0];
return frame.document.body;
}
Iframe中所裝載頁面的打印效果在所裝載頁面設置就可以了,如分頁等。
5.后臺打印
通過建一個隱藏Iframe實現的,當然仍然會有頁面裝載的過程。
下面的函數創建Iframe裝載頁面并打印。如 printHidden(url) //url為頁面地址
function printHidden(url) {
document.body.insertAdjacentHTML("beforeEnd",
"<iframe name=printHiddenFrame width=0 height=0></iframe>");
var doc = printHiddenFrame.document;
doc.open();
doc.write("<body onload=/"parent.onprintHiddenFrame()/">");
doc.write("<iframe name=printMe width=0 height=0 src=/"" +
url + "/"></iframe>");
doc.write("</body>");
doc.close();
}
function onprintHiddenFrame() {
function onfinish() {
printHiddenFrame.outerHTML = "";
if ( window.onprintcomplete ) window.onprintcomplete();
}
printFrame(printHiddenFrame.printMe, onfinish);
}
它用到了printFrame,所以別忘了引用前面的函數。
以下為demo:
<html>
<head>
<title>報表</title>
<object id="WebBrowser"
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height="0"
width="0">
</object>
<style media="print" type="text/css">
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
</head>
<body>
<div class="Noprint">
<input type="button" value="print"
onclick="document.all.WebBrowser.ExecWB(6,6)">
<input type="button" value="printset"
onclick="document.all.WebBrowser.ExecWB(8,1)">
<input type="button" value="view"
onclick="document.all.WebBrowser.ExecWB(7,1)">
<input type="button" value="frame"
onclick="printHidden(FrameId)">
</div>
<div class="PageNext">
1
</div>
<div class="PageNext">
2
</div>
<iframe style="visibility: visible" diplay="none"name="FrameId" width="100%"
height="30%" src="2.html"></iframe>
</body>
</html>
<script type="text/Javascript">
window.print = printFrame;
// main stuff
function printFrame(frame, onfinish) {
if ( !frame ) frame = window;
function execOnFinish() {
switch ( typeof(onfinish) ) {
case "string": execScript(onfinish); break;
case "function": onfinish();
}
if ( focused && !focused.disabled ) focused.focus();
}
if (( frame.document.readyState !== "complete") &&( !frame.document.confirm("The document to print is not downloaded yet! Continue with printing?") ))
{
execOnFinish();
return;
}
var eventScope = printGetEventScope(frame);
var focused = document.activeElement;
window.printHelper = function() {
execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
printFireEvent(frame, eventScope, "onafterprint");
printWB.outerHTML = "";
execOnFinish();
window.printHelper = null;
}
document.body.insertAdjacentHTML("beforeEnd",
"<object id=/"printWB/" width=0 height=0 /
classid=/"clsid:8856F961-340A-11D0-A96B-00C04FD705A2/">");
printFireEvent(frame, eventScope, "onbeforeprint");
frame.focus();
window.printHelper = printHelper;
setTimeout("window.printHelper()", 0);
}
// helpers
function printIsNativeSupport() {
var agent = window.navigator.userAgent;
var i = agent.indexOf("MSIE ")+5;
return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}
function printFireEvent(frame, obj, name) {
var handler = obj[name];
switch ( typeof(handler) ) {
case "string": frame.execScript(handler); break;
case "function": handler();
}
}
function printGetEventScope(frame) {
var frameset = frame.document.all.tags("FRAMESET");
if ( frameset.length ) return frameset[0];
return frame.document.body;
}
function printHidden(url) {
document.body.insertAdjacentHTML("beforeEnd",
"<iframe name=printHiddenFrame width=0 height=0></iframe>");
var doc = printHiddenFrame.document;
doc.open();
doc.write("<body onload=/"parent.onprintHiddenFrame()/">");
doc.write("<iframe name=printMe width=0 height=0 src=/"" +
url + "/"></iframe>");
doc.write("</body>");
doc.close();
}
function onprintHiddenFrame() {
function onfinish() {
printHiddenFrame.outerHTML = "";
if ( window.onprintcomplete ) window.onprintcomplete();
}
printFrame(printHiddenFrame.printMe, onfinish);
}
</script>

JavaScript技術web 頁面分頁打印的實現,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 国内精品久久久久影院男同志 | 久久国产精品永久免费网站 | 九九精品在线播放 | 精子射到丝袜上图 | 国产无遮挡又黄又爽在线视频 | 国产精品午夜小视频观看 | 精品欧美18videosex欧美 | 国产精品高潮AV久久无码 | 久久青草在线视频精品 | 色欲AV色欲AV久久麻豆 | DASD-700美谷朱里| 狠狠狠色丁香婷婷综合久久 | 狠狠色欧美亚洲狠狠色www | 国产AV天堂亚洲AV麻豆 | 成年人免费观看的视频 | 亚洲高清中文字幕免费 | 久久午夜夜伦痒痒想咳嗽P 久久午夜夜伦鲁鲁片无码免费 | 国产麻豆精品传媒AV国产在线 | 中文字幕乱偷无码AV蜜桃 | 无码国产精品高潮久久9 | 国产免费人成在线视频有码 | 快播欧美大片 | 一区二区三区国产亚洲网站 | 亚洲福利天堂网福利在线观看 | 又黄又爽又无遮挡在线观看免费 | 免费果冻传媒2021在线看 | 成人在线视频国产 | 高h乱一受多攻男男 | 人妻熟女斩五十路0930 | 国产精品自产拍在线观看网站 | 国色天香视频在线社区 | 亚洲国产日韩欧美视频二区 | 动漫护士被乳羞羞漫 | 国产精品igao视频网网址 | 好满射太多了装不下了视频 | 青青青青久久久久国产的 | 午夜伦理yy44008影院 | 伊人久久久久久久久久 | 免费人成视频19674不收费 | 哒哒哒影院在线观看免费高清 | 六月婷婷国产精品综合 |